R 中的 GSL 库 - 找不到符号

GSL library in R - Symbol not found

作为新用户,我对 C 的了解非常有限,我有一些用 C 编写的代码需要在 R 中使用。我尝试使用 "gsl_integration" 库。因为代码需要传递给可能没有安装 GSL 库的不同人,所以我创建了我的 "integration.h" 文件,其中包含 "gsl_integration" 库中的所有函数和依赖项。我可以使用

编译我的 code.c 文件
$ R CMD SHLIB code.c

这是我得到的输出

 -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

当我尝试 dyn.load R 中的 "code.so" 文件时,出现以下错误

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

我猜 R 试图找到库的方式有问题吗? 我有什么解决办法吗?

您没有link反对 GSL。

一个你可能想模仿其设置的包是我的 RcppZiggurat 包,它是这样做的:

PKG_LIBS = `$(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"`

ie 它有一个函数,通过调用我的 RcppGSL 包返回正确的库位置,该包在包启动时学习该位置。