rcpp - 将 Rcpp 链接到 interp2d(GSL 类型库)

标签 rcpp gsl

我需要一些帮助来解决在我没有管理员权限的 Linux 系统上安装 Rcpp 软件包时遇到的链接器错误。简而言之,我收到此错误:

relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

我有一个使用外部库的文件 solve.cpp interp2d ,这又具有 GSL 依赖性。我通过 [[Rcpp::depends(RcppArmadillo,RcppGSL)]]DESCRIPTION 指定我的依赖项。我的 Makevars 类似于 RcppGSL 包中的 Makevars,但添加了 linterp2d 标志:

PKG_CPPFLAGS = -W $(GSL_CFLAGS) $(LOCAL_INCLUDE)
PKG_LIBS += $(GSL_LIBS) $(LOCAL_LIBS) -linterp2d $(RCPP_LDFLAGS) 

我定义环境变量的地方

export LOCAL_INCLUDE="-I/data/uctpfos/local/include/"
export LOCAL_LIBS="-L/data/uctpfos/local/lib/"

在系统上。

我执行R CMD INSTALL bkPackage并看到:

g++ -I/cm/shared/apps/R/3.0.1/lib64/R/include -DNDEBUG -W -I/cm/shared/apps/gsl/1.15/include -I/data/uctpfos/local/include -fPIC -I/usr/local/include -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppArmadillo/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppGSL/include"   -fpic  -O3 -fPIC -c RcppExports.cpp -o RcppExports.o

g++ -I/cm/shared/apps/R/3.0.1/lib64/R/include -DNDEBUG -W -I/cm/shared/apps/gsl/1.15/include -I/data/uctpfos/local/include -fPIC -I/usr/local/include -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppArmadillo/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppGSL/include"   -fpic  -O3 -fPIC -c solve.cpp -o solve.o

问题出现在链接步骤之后:

g++ -shared -L/usr/local/lib64 -o bkPackage.so RcppExports.o solve.o -L/cm/shared/apps/gsl/1.15/lib -lgsl -lgslcblas -lm -L/data/uctpfos/local/lib -linterp2d -L/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/lib -lRcpp -Wl,-rpath,/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/lib

错误如下:

/usr/bin/ld: /data/uctpfos/local/lib/libinterp2d.a(interp2d_spline.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC 
/data/uctpfos/local/lib/libinterp2d.a: could not read symbols: Bad value

正如你所看到的,我用 -fPIC 编译了它,所以不可能是这样。

最佳答案

它提示libinterp2d.a不是用-fPIC编译的;您确定它也是使用 -fPIC 编译的吗?

此外,您的标志中似乎都有 -fpic-fPIC ;您可能只需要-fPIC。我认为 R 实际上确保默认情况下处于打开状态。

关于rcpp - 将 Rcpp 链接到 interp2d(GSL 类型库),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21094740/

相关文章:

RcppEigen - 这个矩阵乘法有什么问题?

c++ - 如何使用 R 和 RCPP 编译 dll?

r - 等效于 Rcpp 的 lineprof

c++ - C++ 中带有 Wrapper 函数的 GSL 错误处理程序状态

c - 将 GNU 科学库与 Code::Blocks 一起使用时出错

c - GSL 特征值顺序

r - 从 Rcpp 中调用 igraph

Rcpp 链接到外部库 (NLopt)

c - 使用 GSL 的双摆解决方案

c++ - 使用 cmake 设置 gsl 时出现问题