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:
there symbols leading underscores in r. symbols fail link routinely used
putrngstate()
,rf_rchisq()
, ... maybe need fix switch accidentally set?it not clear post whether want load r dynamic extension, or whether want write standalone program using these r functions. can both.
calling self-written function can trivial. leaning on rcpp, can
cppfunction('double foo(int df) { return rf_rchisq(df); }')
, callfoo(3)
repeatedly (because rcpp deals rng state viarngscope
class).if want standalone, @ writing r extensions manual , rmathlib library. have posted small examples before.
Comments
Post a Comment