c - Undefined symbols for architecture x86_64: getRNGstate() and putRNGstate() -


i'm writing gibbs function in c , want use random number functions such rnorm().

my code this:

#include <stdio.h> #include <string.h> #include <r.h> #include <rmath.h> void foo(int *nin, double *x) {     int n = nin[0];      int i;     getrngstate();      (i=0; i<n; i++)     {         x[i] = rchisq(2);         rprintf("%f\n",x[i]);     }     // exit r random-gen routine     putrngstate(); } 

however when tried build in xcode, error messages are:

> undefined symbols architecture x86_64:   "_getrngstate", > referenced from: >       _gibbs in main.o   "_putrngstate", referenced from: >       _gibbs in main.o   "_rf_rchisq", referenced from: >       _gibbs in main.o   "_rf_rnorm", referenced from: >       _gibbs in main.o   "_rf_runif", referenced from: >       _gibbs in main.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see > invocation) 

i'm using xcode , know have both r , r64bit. on terminal $r runs r64bit , aquamacs runs r64bit. don't know whether collide on different versions , if so, how can convince xcode refer r correctly?

btw found r.h , rmath.h files in @ least 3 places! don't know path should relocate in xcode! currently i'm adding header path same 3rd one. , #include works fine.

r.frameworks/headers r.frameworks/versions/2.15/resources/include r.frameworks/versions/current/resources/include 

etc

but either way, c function without getting rnorm()-like functions work , r can use through dyn.load().

so please help!

much appreciated!

your question incomplete , not reproducible lack of actual code. there few issues can suggest:

  1. there symbols leading underscores in r. symbols fail link routinely used putrngstate(), rf_rchisq(), ... maybe need fix switch accidentally set?

  2. it not clear post whether want load r dynamic extension, or whether want write standalone program using these r functions. can both.

  3. calling self-written function can trivial. leaning on rcpp, can cppfunction('double foo(int df) { return rf_rchisq(df); }') , call foo(3) repeatedly (because rcpp deals rng state via rngscope class).

  4. if want standalone, @ writing r extensions manual , rmathlib library. have posted small examples before.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -