本文介绍了创建 R 包时出错:dyn.load(file, DLLpath = DLLpath, ...) 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个名为 CVOC 的 R 包.它包含 C++ 代码并使用来自 C 库 gmp 的高精度算法.

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) 使用 Rcpp::Rcpp.package.skeleton 创建包骨架.

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

2) 将需要的文件,例如DESCRIPTION、NAMESPACE、Makevars等复制到正确的文件夹中

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

3) 使用 roxygen2::roxygenise() 创建 .Rd 文档文件

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

4) 使用 R CMD check 检查 R 包

4) checking the R-package using R CMD check

5) 使用 R CMD build 构建 R 包

5) building the R-package using R CMD build

当我运行 R CMD 检查CVOC"时出现以下错误消息:

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’

包括 bash 脚本 createCVOC.sh 在内的所有必要文件都可以在 https://github 存储库中找到github.com/SchroederFabian/CVOC.

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

非常感谢任何帮助.

推荐答案

有些地方不对,让我们检查一下.请提供指向您的 src/Makevars 这确实表明你有

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

本质上你混淆了

  • 允许您添加"到现有规则的 PKG_* 变体与普通的(即编译你想要PKG_CXXFLAGS)和

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

你在需要 PKG_LIBS 时使用了 PKG_CXXFLAGS.

you used PKG_CXXFLAGS when you needed PKG_LIBS.

尝试添加

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'.

这篇关于创建 R 包时出错:dyn.load(file, DLLpath = DLLpath, ...) 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 03:25