作为新用户,我对 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
当我尝试在 R 中 dyn.load“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 尝试查找库的方式有问题? 有什么想法可以解决这个问题吗?
最佳答案
您没有链接到 GSL。
您可能想要模仿的一个包是我的 RcppZiggurat执行此操作的包:
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"`
即它有一个函数通过调用我的 RcppGSL 返回正确的库位置。包在其包启动时学习该位置一次。
关于r - R 中的 GSL 库 - 未找到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39153138/