开发者

Standalone Rmath.h in native C/C++ program [2]

According to R-admin.pdf, I built the standalone Rmath library on my Mac. The first test program seemed compiled and linked well, but generated an error message. The followings are my procedures:

$ cc -o test test.c -I /library/frameworks/r.framework/headers 
-L/us开发者_运维知识库ers/ed/downloads/r-2.13.1/src/nmath/standalone/ -lRmath -lm
$ ./test
dyld: Library not loaded: libRmath.dylib
  Referenced from: .....
  Reason: image not found
Trace/BPT trap
$

Thanks in advance.


I found a way to compile and link C code including Rmath.h. When you choose default installation, the path for the header is /library/frameworks/r.framework/headers, and the path for the library is /library/frameworks/r.framework/libraries.

$ gcc -I/library/frameworks/r.framework/headers -c test.c

$ gcc -L/library/frameworks/r.framework/libraries test.o -lRmath -o progname

Single line implementation is also convenient:

$ gcc -I/library/frameworks/r.framework/headers test.c \
-L/library/frameworks/r.framework/libraries -lRmath -o progname

I found that Objective-C program can include standalone Rmath.h as well. Implementation is as follows: (name of the objective-c program is 'test.m.')

$ gcc -framework Foundation -I/library/frameworks/r.framework/headers test.m 
-L/library/frameworks/r.framework/libraries -lRmath -o progname

I added this comment in the hope that it will be useful...


I'm not a mac guy, but you need to ensure your program finds libRmath.dylib. On Linux you would set LD_LIBRARY_PATH...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜