简体   繁体   English

dyn.load(dllfile) 中的错误 — 构建链接到 Rcpp 的 package 时出现问题

[英]Error in dyn.load(dllfile) — problem with building a package linking to Rcpp

My package will not install, either on my machine or on travis-ci.org.我的 package 无法安装在我的机器上或 travis-ci.org 上。 The only update from the version on CRAN is that I added a vignette. CRAN 版本的唯一更新是我添加了一个小插图。 I have been following the examples of Rcpp - package and R-packages;我一直在关注Rcpp - packageR-packages 的示例; compiled code .编译代码

The error is related to these prior questions but not a duplicate.该错误与这些先前的问题有关,但不是重复的。

  1. Q40922814 -- problem here was the use of both C and C++ code. Q40922814 - 这里的问题是同时使用 C 和 C++ 代码。 I only use C++ code我只使用 C++ 代码
  2. Q36952571 -- I'm on Mac OS, so no access to ldconfig , though perhaps my problem is related. Q36952571 - 我在 Mac OS 上,所以无法访问ldconfig ,尽管我的问题可能与此有关。

Error:错误:

from the package directory:从 package 目录:

# Restarting R session...
> Rcpp::compileAttributes()
> devtools::document()     # a similar error using devtools::install()
Updating imputeMulti documentation
Loading imputeMulti
Re-compiling imputeMulti
─  installing *source* package ‘imputeMulti’ ...
   ** using staged installation
   ** libs
   g++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -std=c++0x -c RcppExports.cpp -o RcppExports.o
   g++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -std=c++0x -c count_compare.cpp -o count_compare.o
   g++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -std=c++0x -c utilities_rcpp.cpp -o utilities_rcpp.o
   g++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o imputeMulti.so RcppExports.o count_compare.o utilities_rcpp.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
   installing to /private/var/folders/6h/px5b6ds15b72srhkxc42k9drt2vmnc/T/Rtmpa4w8vb/devtools_install_876345d52e22/00LOCK-imputeMulti/00new/imputeMulti/libs
   ** checking absolute paths in shared objects and dynamic libraries
─  DONE (imputeMulti)
Error in dyn.load(dllfile) : 
  unable to load shared object './imputeMulti/src/imputeMulti.so':
  dlopen(./imputeMulti/src/imputeMulti.so, 6): Symbol not found: _imputeMulti_supDistC
  Referenced from: ./imputeMulti/src/imputeMulti.so
  Expected in: flat namespace
 in ./imputeMulti/src/imputeMulti.so

And session info:和 session 信息:

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      compiler_3.6.3    prettyunits_1.1.1 remotes_2.1.1     tools_3.6.3       bit_1.1-15.2     
 [7] testthat_2.3.2    digest_0.6.25     pkgbuild_1.0.7    pkgload_1.0.2     RSQLite_2.2.0     memoise_1.1.0    
[13] rlang_0.4.6       DBI_1.1.0         cli_2.0.2         rstudioapi_0.11   parallel_3.6.3    xfun_0.13        
[19] withr_2.2.0       stringr_1.4.0     roxygen2_7.1.0    knitr_1.28        xml2_1.3.2        vctrs_0.2.4      
[25] desc_1.2.0        fs_1.4.1          gtools_3.8.2      devtools_2.3.0    bit64_0.9-7       rprojroot_1.3-2  
[31] glue_1.4.0        R6_2.4.1          processx_3.4.2    fansi_0.4.1       imputeMulti_0.7.1 sessioninfo_1.1.1
[37] blob_1.2.1        callr_3.4.3       purrr_0.3.4       magrittr_1.5      backports_1.1.6   ps_1.3.2         
[43] ellipsis_0.3.0    usethis_1.6.0     assertthat_0.2.1  stringi_1.4.6     crayon_1.3.4  

> devtools::build() # works 

code代码

My package: imputeMulti我的 package: imputeMulti

I have the following C++ files in src/我在src/中有以下 C++ 文件

# utilities_rcpp.cpp
#include <Rcpp.h>
using namespace Rcpp;

<two minor functions>

# count_compare.cpp
#include <Rcpp.h>
using namespace Rcpp;

<one minor function>

I also have我也有

# imputeMulti-package.R
## usethis namespace: start
#' @importFrom Rcpp sourceCpp, evalCpp
## usethis namespace: end
NULL

#' @useDynLib imputeMulti

.onUnload <- function (libpath) {
  library.dynam.unload('imputeMulti', libpath)
}

My best guess is that the error is related to Q36952571, but I am unsure how to resolve.我最好的猜测是该错误与 Q36952571 有关,但我不确定如何解决。 Any help would be greatly appreciated.任何帮助将不胜感激。

I think, based on a quick poke, that your package is borked.我认为,基于快速戳,你的 package 是无聊的。

The install step fails on安装步骤失败

** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘imputeMulti’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/site-library/00LOCK-imputeMulti/00new/imputeMulti/libs/imputeMulti.so':
  /usr/local/lib/R/site-library/00LOCK-imputeMulti/00new/imputeMulti/libs/imputeMulti.so: undefined symbol: imputeMulti_supDistC
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/site-library/imputeMulti’
Warning message:
In install.packages(pkgs = f, lib = lib, repos = if (isMatchingFile(f)) NULL else repos) :
  installation of package ‘imputeMulti_0.7.1.tar.gz’ had non-zero exit status
edd@rob:/tmp/imputeMulti(master)$

Ie we miss a symbol imputeMulti_supDistC which you call, and you are doing that wrong.我们错过了您调用的符号imputeMulti_supDistC ,而您做错了。 With Rcpp and its (awesome) compileAttributes() you do not invoke .Call() as you did here.使用 Rcpp 及其(很棒的) compileAttributes()不会像在此处那样调用.Call() You call a provide R wrapper.您调用提供 R 包装器。

You made that mistake twice, and this fixed it:你犯了两次这个错误,这解决了它:

edd@rob:/tmp/imputeMulti(master)$ git diff R/int-count_levels.R
diff --git a/R/int-count_levels.R b/R/int-count_levels.R
index a4ce4cc..9e749cc 100755
--- a/R/int-count_levels.R
+++ b/R/int-count_levels.R
@@ -4,7 +4,8 @@
 # wrapper to supDistC to move error checking outside of C++
 supDist <- function(x,y) {
   if (length(x) != length(y)) stop("Length of x and y differ.")
-  .Call('imputeMulti_supDistC', PACKAGE = 'imputeMulti', x, y)
+  #.Call('imputeMulti_supDistC', PACKAGE = 'imputeMulti', x, y)
+  supDistC(x, y)
 }

 # convert a factor-vector to an integer vector, where the integers correspond
@@ -91,7 +92,8 @@ mx_my_compare <- function(mat_x, mat_y) {
   mat_y <- do.call("cbind", lapply(mat_y, fact_to_int))

   ## 1. Run code in C
-  .Call('imputeMulti_xy_compare', PACKAGE = 'imputeMulti', mat_x, mat_y)
+  #.Call('imputeMulti_xy_compare', PACKAGE = 'imputeMulti', mat_x, mat_y)
+  xy_compare(mat_x, mat_y)
   # mat_to_mat_compare(mat_x, mat_y, na.rm= TRUE)
 }

edd@rob:/tmp/imputeMulti(master)$ 

Make those simplifications, run compileAttributes() to update the two RcppExports files, and be happy.进行这些简化,运行compileAttributes()来更新两个RcppExports文件,然后就开心了。

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

相关问题 Rcpp/RcppGSL:dyn.load(dllfile)中的错误; - Rcpp/RcppGSL: Error in dyn.load(dllfile); 将包与Rcpp链接的dyn.load错误 - dyn.load error linking a package with Rcpp Mac Rcpp软件包中dyn.load中的错误 - error in dyn.load in Rcpp package in mac 使用RCPP软件包创建R软件包时出错:macOS中dyn.load中的错误 - Error creating R package using RCPP package : Error in dyn.load in macOS dyn.load中的错误(文件,DLLpath = DLLpath,...) - Error in dyn.load(file, DLLpath = DLLpath, …) 错误:package 或 dyn.load(文件,DLLpath = DLLpath,...)中的“gmm”的命名空间加载失败:无法加载共享 object - Error: package or namespace load failed for ‘gmm’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object Gurobi 包无法在 Ubuntu 14.04 中加载,dyn.load(file, DLLpath = DLLpath, ...) 出错: - Gurobi package does not load in Ubuntu 14.04, Error in dyn.load(file, DLLpath = DLLpath, …) : 创建R包时出错:dyn.load中的错误(文件,DLLpath = DLLpath,...) - Error creating R package: Error in dyn.load(file, DLLpath = DLLpath, …) 从Rith中的github安装包时出错.dyn.load中的错误 - Error while installing package from github in R. Error in dyn.load 无法安装leaps包,dyn.load中的错误(文件,DLLpath = DLLpath,...)[Mac OSX] - Unable to install leaps package, Error in dyn.load(file, DLLpath = DLLpath, …) [Mac OSX]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM