本文介绍了在Linux上使用g ++编译RInside程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过RPM(与Yast)一起安装了R.
anisha@linux-y3pi:~> locate RInside.so
/usr/lib64/R/library/RInside/lib/libRInside.so
/usr/lib64/R/library/RInside/libs/RInside.so
anisha@linux-y3pi:~> locate Rcpp.so
/usr/lib64/R/library/Rcpp/lib/libRcpp.so
/usr/lib64/R/library/Rcpp/libs/Rcpp.so
我要编译的文件(rinsidetest.cpp
)包含:
The file (rinsidetest.cpp
) that I wish to compile contains:
#include <RInside.h>
#include <Rcpp.h>
int main (int argc, char *argv[])
{
RInside R (argc, argv);
return 0;
}
这是我的编译方式:
Here's how I compile it:
anisha@linux-y3pi:~> g++ rinsidetest.cpp -I /usr/lib64/R/library/RInside/include/ -I /usr/lib64/R/library/Rcpp/include/ -I /usr/lib64/R/include/ -L /usr/lib64/R/library/RInside/libs/ -L /usr/lib64/R/library/Rcpp/libs/
/tmp/ccUfdjgZ.o: In function `main':
rinsidetest.cpp:(.text+0xb7): undefined reference to `RInside::RInside(int, char const* const*, bool)'
rinsidetest.cpp:(.text+0xc8): undefined reference to `RInside::~RInside()'
collect2: ld returned 1 exit status
R信息:
R information:
> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tcltk_2.15.1 tools_2.15.1
>
RInside
版本:0.2.6
Rcpp
版本:0.9.13
RInside
version: 0.2.6
Rcpp
version: 0.9.13
是否有解决此问题的方法,或者我必须"删除rpm安装并通过从源代码进行编译来启动所有内容?
编辑
anisha@linux-y3pi:~/Desktop/abc> g++ rinsidetest.cpp -I /usr/lib64/R/library/RInside/include/ -I /usr/lib64/R/library/Rcpp/include/ -I /usr/lib64/R/include/ -L /usr/lib64/R/library/RInside/lib/ -L /usr/lib64/R/library/Rcpp/lib/ -lRInside
anisha@linux-y3pi:~/Desktop/abc> ls
a.out rinsidetest.cpp
anisha@linux-y3pi:~/Desktop/abc> ./a.out
./a.out: error while loading shared libraries: libRInside.so: cannot open shared object file: No such file or directory
推荐答案
尝试将以下内容添加到g ++版本的末尾
Try adding the following to the end of your g++ build
-lRInside -lRcpp
让您拥有
g++ rinsidetest.cpp -I /usr/lib64/R/library/RInside/include/ -I /usr/lib64/R/library/Rcpp/include/ -I /usr/lib64/R/include/ -L /usr/lib64/R/library/RInside/libs/ -L /usr/lib64/R/library/Rcpp/libs/ -lRInside -lRcpp
目前看来,您似乎并没有链接到所需的库.当您有一个名为libXYZ
的库时,您需要使用带有-lXYZ
的g ++链接到它,看来您尚未完成.这可能会解决问题
As it stands it doesnt appear that you are linking to the library you need. When you have a library named libXYZ
you need to link to it using g++ with -lXYZ
which it appears you have not done. This may fix the problem
这篇关于在Linux上使用g ++编译RInside程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!