dyn.load error linking a package with Rcpp

我们两清 提交于 2020-07-18 08:06:49

问题


I've made an R package with Rcpp, to use the methods of a library I programmed in c++.

I've R running on the last version:

R version 3.2.5 (2016-04-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04 LTS

I'm executing the following instruction to install my package:

> install.packages("mypackage", repos = NULL)

The package compiles well, I have the .o files of my source code, but in the linking phase I got the error:

* installing *source* package ‘rbdd’ ...
** libs
make: No se hace nada para 'all'.
installing to /home/sergio/R/x86_64-pc-linux-gnu-library/3.2/mypackage/libs
** R
** preparing package for lazy loading
** help
Warning: /home/sergio/R/mypackage/man/mypackage-package.Rd:27: All text must be in a section
Warning: /home/sergio/R/mypackage/man/mypackage-package.Rd:28: All text must be in a section
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
unable to load shared object '/home/sergio/R/x86_64-pc-linux-gnu-library/3.2/mypackage/libs/mypackage.so':
/home/sergio/R/x86_64-pc-linux-gnu-library/3.2/mypackage/libs/mypackage.so: undefined symbol: _ZN4cudd12defaultErrorENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE
Error: loading failed
Ejecución interrumpida
ERROR: loading failed

mypackge.so is created in the src folder of my package.

I've got a Makevars file (in src, too) with the following content:

PKG_CPPFLAGS=-I./buddy-2.5/src -I./cudd-3.0.0/cudd -I./cudd-3.0.0/mtr -I./cudd-3.0.0/cplusplus -I./cudd-3.0.0/dddmp -I./cudd-3.0.0/util -I./cudd-3.0.0 -isystem /usr/include/c++/v1 -std=c++11
PKG_LIBS=-lc++ -L/lib

and my NAMESPACE file has the lines:

useDynLib(mypackage)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)

Someone knows how to solve this problem?


回答1:


I am a little concerned about

PKG_LIBS=-lc++ -L/lib

Did you really mean /lib? If it is your library, a more common place would be /usr/local/lib which is also search by default.

But, and that is a BIG but, you also need to understand what you need to do for ldconfig for the proper setup of libfoo.so, libfoo.so.$MAJOR and so on. I taught myself that many moons ago from a Linux HOWTO.

If and when that is setup right, you can link it to R via Rcpp. Otherwise maybe stick with system libraries, or package-local static libraries. That approach will also make your package more portable.




回答2:


The problem was I am consumming external libs, and I must compile it and execute ldconfig before compile my R library.



来源:https://stackoverflow.com/questions/36952571/dyn-load-error-linking-a-package-with-rcpp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!