将 Rcpp 链接到 interp2d(GSL 类型库) [英] Linking Rcpp to interp2d (GSL-type library)

查看:48
本文介绍了将 Rcpp 链接到 interp2d(GSL 类型库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need some help with a linker error I get during installation of an Rcpp package on a linux system where I don't have admin rights. In a nutshell, I get this error:

重新定位R_X86_64_32针对`.rodata'不能在创建共享对象时使用;用 -fPIC 重新编译

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

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

I have a file solve.cpp that uses external library interp2d, which in turn has a GSL dependency. I specify my dependencies via [[Rcpp::depends(RcppArmadillo,RcppGSL)]] and in the DESCRIPTION. My Makevars is like the one from the RcppGSL package, with the addition of the linterp2d flag:

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

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

The problems appears after that in the linking step:

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 编译了它,所以不可能.

As you can see I compiled this with -fPIC, so that can't be it.

推荐答案

有人抱怨 libinterp2d.a 没有使用 -fPIC 编译;你确定它也是用 -fPIC 编译的吗?

It's complaining that libinterp2d.a was not compiled with -fPIC; are you sure that was also compiled with -fPIC on?

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

Also, it seems you both have -fpic and -fPIC in your flags; you probably just want -fPIC. I think R actually ensures that's on by default.

这篇关于将 Rcpp 链接到 interp2d(GSL 类型库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆