问题
my knowledge in C is very limited as a new users, I have some code written in C that I need to use in R. I try to use the "gsl_integration" library. Because the code needs to be passed around to different people that might not have the GSL library installed, I have created my "integration.h" file that includes all the functions and dependencies from the "gsl_integration" library. I am able to compile my code.c file using the
$ R CMD SHLIB code.c
and this is the output I get
-I/Library/Frameworks/R.framework/Resources/include -DNDEBUG
-I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include
-fPIC -Wall -mtune=core2 -g -O2 -c code.c -o code.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o code.so code.o
-F/Library/Frameworks/R.framework/..
-framework R -Wl,-framework -Wl,CoreFoundation
When I try to dyn.load the "code.so" file in R I get the following error
Error in dyn.load("code.so") :
unable to load shared object '/Users/Thodoris/Desktop/Int_C/code.so':
dlopen(/Users/Thodoris/Desktop/Int_C/code.so, 6): Symbol not found: _gsl_integration_qags
Referenced from: /Users/Thodoris/Desktop/Int_C/code.so
Expected in: flat namespace
in /Users/Thodoris/Desktop/Int_C/code.so
I guess is something wrong with the way R trying to find the library? Any ideas how I can fix that?
回答1:
You didn't link against the GSL.
One package whose setup you may want to mimic is my RcppZiggurat package which does this:
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"`
ie it has a function returning the proper library location by virtue of a call to my RcppGSL package which learns that location once at its package startup.
来源:https://stackoverflow.com/questions/39153138/gsl-library-in-r-symbol-not-found