Error creating R package: Error in dyn.load(file, DLLpath = DLLpath, …)

夙愿已清 提交于 2021-01-28 08:31:13

问题


I am creating an R package called CVOC. It includes C++ code and uses high precision arithmetic from the C library gmp.

The package is to be created by the following steps:

1) using Rcpp::Rcpp.package.skeleton to create the package skeleton.

2) copying the required files, such as DESCRIPTION, NAMESPACE, Makevars, etc. , into the correct folders

3) creating the .Rd documentation files using roxygen2::roxygenise()

4) checking the R-package using R CMD check

5) building the R-package using R CMD build

When I run R CMD check "CVOC" the following error message comes up:

* installing *source* package ‘CVOC’ ...
** libs
g++ -std=c++11 -I/usr/share/R/include -DNDEBUG   -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/RcppMP/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/BH/include"   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
g++ -std=c++11 -I/usr/share/R/include -DNDEBUG   -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/RcppMP/include" -I"/home/fabian/R/x86_64-pc-linux-gnu-library/3.2/BH/include"   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c etcND.cpp -o etcND.o
g++ -std=c++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o CVOC.so RcppExports.o etcND.o -L/usr/lib/R/lib -lR
installing to /home/fabian/Desktop/CVOCcreate/CVOC.Rcheck/CVOC/libs
** R
** preparing package for lazy loading
** help
*** 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/fabian/Desktop/CVOCcreat/CVOC.Rcheck  /CVOC/libs/CVOC.so':
  /home/fabian/Desktop/CVOCcreate/CVOC.Rcheck/CVOC/libs/CVOC.so:            
undefined symbol: __gmp_bits_per_limb
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/fabian/Desktop/CVOCcreate/CVOC.Rcheck/CVOC’

All the necessary files including the bash script createCVOC.sh can be found on the github repository at https://github.com/SchroederFabian/CVOC.

Any help is much appreciated.


回答1:


Something is not right, so let us check. You kindly provide a link to your src/Makevars which does in fact show that you have

CXXFLAGS= -lgmpxx -lgmp 

yet in the log you show in your question no such linking takes place:

g++ -std=c++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions \
   -Wl,-z,relro -o CVOC.so RcppExports.o etcND.o -L/usr/lib/R/lib -lR

In essence you confused

  • the PKG_* variants which allow you to "add" to existing rules with the plain ones (ie for compilation you want PKG_CXXFLAGS) and

  • you used PKG_CXXFLAGS when you needed PKG_LIBS.

Try adding

PKG_LIBS= -lgmpxx -lgmp 

and try again. Check what linking step happens. You should have the required libraries added, and no longer suffer from 'unknown symbol'.



来源:https://stackoverflow.com/questions/41599150/error-creating-r-package-error-in-dyn-loadfile-dllpath-dllpath

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