简体   繁体   English

RCPP错误:包安装时未定义的符号:_ZTIN4Rcpp7RObjectE

[英]RCPP error: undefined symbol: _ZTIN4Rcpp7RObjectE on package install

Using the default hello world program through Rcpp.package.skeleton I 'sometimes' get this error on install. 通过Rcpp.package.skeleton使用默认的hello world程序我有时会在安装时遇到此错误。

Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/home/usrname/R/x86_64-pc-linux-gnu-library/3.0/helloWorld/libs/helloWorld.so': /home/usrname/R/x86_64-pc-linux-gnu-library/3.0/helloWorld/libs/helloWorld.so: undefined symbol: _ZTIN4Rcpp7RObjectE. dyn.load中的错误(文件,DLLpath = DLLpath,...):无法加载共享对象'/home/usrname/R/x86_64-pc-linux-gnu-library/3.0/helloWorld/libs/helloWorld.so' :/home/usrname/R/x86_64-pc-linux-gnu-library/3.0/helloWorld/libs/helloWorld.so:unfined defined symbol:_ZTIN4Rcpp7RObjectE。

By sometimes I mean, in about 10 tries only once did it get that error on the first time installing although in the end after some tweaks every package eventually gets the error and even if all changes are removed from the code and all the .o,.so and the tar file deleted, and the library uninstalled in R, the package will not build again. 有时我的意思是,在大约10次尝试中只有一次它在第一次安装时得到了该错误,尽管最终在经过一些调整之后每个包最终都会得到错误,即使所有更改都从代码和所有.o中删除了, .so和tar文件被删除,并且在R中卸载了库,该包将不会再次构建。

My end goal is to include some zlib functions into some code using the -lz compile option so when I say 'some tweaks' to the hello_world they would be: 我的最终目标是使用-lz编译选项将一些zlib函数包含到某些代码中,所以当我对hello_world说'some tweaks'时,它们将是:
1. add -lz to the PKG_LIBS var in Makevars 1.将-lz添加到Makevars中的PKG_LIBS var
2. Add #include to the .cpp file 2.将#include添加到.cpp文件中
3. Create a const char* a 3.创建一个const char * a
4. attempt to use a to call gzopen(a,a) 4.尝试用a来调用gzopen(a,a)

My process is 我的过程是
1. in R: Rcpp.package.skeleton("testPackage", attributes = TRUE) 1.在R中:Rcpp.package.skeleton(“testPackage”,attributes = TRUE)
2. in terminal: R CMD build testPackage 2.在终端:R CMD构建testPackage
3. in terminal: R CMD INSTALL testPackage 3.在终端:R CMD INSTALL testPackage

Just to test one last time, I compiled okay, I added the -lz and it was okay, then I added #include and I get the error. 只是为了最后一次测试,我编译好了,我添加了-lz并且没关系,然后我添加了#include并且我得到了错误。 I remove it and still get the error. 我删除它仍然得到错误。

So: 所以:
1. Does anyone know what is causing this error? 1.有谁知道导致此错误的原因是什么?
2. Is there away to repair it so that reverted code installs again? 2.是否需要修复它以便重新安装恢复的代码?
3. If not, is there another way to build zlib into code (sourceCpp seems to work fine). 3.如果没有,是否有另一种方法可以将zlib构建到代码中(sourceCpp似乎工作正常)。

I'm on Ubuntu 12.04.2 LTS 我在Ubuntu 12.04.2 LTS上
R version 3.01 R版本3.01
Rcpp_0.10.3 Rcpp_0.10.3

Update with solution: 更新解决方案:
When editing Makevars I was inadvertently adding an extra set of quotes around the variable as such: 在编辑Makevars时,我无意中在变量周围添加了一组额外的引号:
PKG_LIBS = " $/usr/bin/Rscript -e "Rcpp:::LdFlags()" -lz" PKG_LIBS =“ $/usr/bin/Rscript -e "Rcpp:::LdFlags()" lz”
The correct way to include zlib is to just append -lz to the line: 包含zlib的正确方法是将-lz附加到该行:
PKG_LIBS = $/usr/bin/Rscript -e "Rcpp:::LdFlags()" -lz PKG_LIBS = $/usr/bin/Rscript -e "Rcpp:::LdFlags()" lz
It still remains true that once you get the error, if you try to revert Makevars back to the correct format, you will continue to get the error on install. 一旦你收到错误,如果你试图将Makevars恢复到正确的格式,你仍然会继续在安装时得到错误。 And it also remains true that sometimes (2/6 from my test runs) it will install with the error only to later pop up when including or adding zlib functions into the code. 而且有时候(我的测试运行的2/6)它仍然会安装错误,只有在将zlib函数包含或添加到代码中时才会弹出。

My RcppCNPy package uses zlib. 我的RcppCNPy包使用zlib。 It uses 它用

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

and has code as eg 并且具有例如的代码

cnpy::NpyArray cnpy::npy_gzload(std::string fname) {
    gzFile fp = gzopen(fname.c_str(), "rb");
    if(!fp) {
        Rf_error("npy_gzload: Error! Unable to open file %s!\n",fname.c_str());
    }
    NpyArray arr = gzload_the_npy_file(fp);
    gzclose(fp);
    return arr;
}

Maybe this can serve as a model for you. 也许这可以作为你的模特。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM