簡體   English   中英

cppFunction在Rcpp錯誤

[英]cppFunction in Rcpp error

大約3-4個月前,我曾經平穩地使用Rcpp和RcppArmadillo。 我今天再次嘗試了該操作,由於某種原因,我不斷收到以下錯誤。

> blasso_Rcpp <- cppFunction(depends='RcppArmadillo', code ='
+     arma::mat blasso_cpp(arma::mat x)
+     {
+     return(x);
+ 
+     }
+ 
+ 
+ 
+ ')
Error in dyn.load("/var/folders/6h/ckff_c490ml7_lmhj4xqv3lw0000gp/T//RtmpnVptIY/sourcecpp_553970870d16/sourceCpp_3.so") : 
  unable to load shared object '/var/folders/6h/ckff_c490ml7_lmhj4xqv3lw0000gp/T//RtmpnVptIY/sourcecpp_553970870d16/sourceCpp_3.so':
  dlopen(/var/folders/6h/ckff_c490ml7_lmhj4xqv3lw0000gp/T//RtmpnVptIY/sourcecpp_553970870d16/sourceCpp_3.so, 6): Symbol not found: ___addtf3
  Referenced from: /usr/local/lib/libquadmath.0.dylib
  Expected in: /usr/local/lib/libgcc_s_x86_64.1.dylib
 in /usr/local/lib/libquadmath.0.dylib
> 

不使用RcppArmadillo時不會出現錯誤。

> blasso_Rcpp <- cppFunction(code ='
+     NumericMatrix blasso_cpp(NumericMatrix x)
+     {
+     return(x);
+ 
+     }
+  
+ ')

如果我單獨保存cpp文件,並使用sourceCpp來獲取它,我將遇到同樣的問題。 我已經重新安裝了Xcode,Rcpp,RcppArmadillo。 這是我的會話信息。

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11 (El Capitan)

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     

other attached packages:
[1] RcppArmadillo_0.6.100.0.0 Rcpp_0.12.1              

loaded via a namespace (and not attached):
[1] tools_3.2.2

知道為什么會這樣嗎?

編輯:添加gcc和gfortran信息

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/gfortran/libexec/gcc/x86_64-apple-darwin14/5.1.0/lto-wrapper
Target: x86_64-apple-darwin14
Configured with: ../gcc-5.1.0/configure --prefix=/usr/local/gfortran --with-gmp=/Users/fx/devel/gcc/deps-static/x86_64 --enable-languages=c,c++,fortran,objc,obj-c++ --build=x86_64-apple-darwin14
Thread model: posix
gcc version 5.1.0 (GCC) 

這是從源代碼安裝RcppArmadillo時的錯誤

> install.packages("RcppArmadillo", type = "source")
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://mirrors.nics.utk.edu/cran/src/contrib/RcppArmadillo_0.6.100.0.0.tar.gz'
Content type 'application/x-gzip' length 981341 bytes (958 KB)
==================================================
downloaded 958 KB

* installing *source* package ‘RcppArmadillo’ ...
** package ‘RcppArmadillo’ successfully unpacked and MD5 sums checked
* checking LAPACK_LIBS: divide-and-conquer complex SVD available via R-supplied LAPACK
** libs
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include"  -I../inst/include -fPIC  -Wall -mtune=core2 -g -O2  -c RcppArmadillo.cpp -o RcppArmadillo.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include"  -I../inst/include -fPIC  -Wall -mtune=core2 -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include"  -I../inst/include -fPIC  -Wall -mtune=core2 -g -O2  -c fastLm.cpp -o fastLm.o
clang++ -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 RcppArmadillo.so RcppArmadillo.o RcppExports.o fastLm.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.2/Resources/library/RcppArmadillo/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/RcppArmadillo/libs/RcppArmadillo.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/RcppArmadillo/libs/RcppArmadillo.so, 6): Symbol not found: ___addtf3
  Referenced from: /usr/local/lib/libquadmath.0.dylib
  Expected in: /usr/local/lib/libgcc_s_x86_64.1.dylib
 in /usr/local/lib/libquadmath.0.dylib
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/RcppArmadillo’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/RcppArmadillo’

The downloaded source packages are in
    ‘/private/var/folders/6h/ckff_c490ml7_lmhj4xqv3lw0000gp/T/Rtmp82GBGH/downloaded_packages’
Warning message:
In install.packages("RcppArmadillo", type = "source") :
  installation of package ‘RcppArmadillo’ had non-zero exit status

在這里工作正常:

R> Rcpp::cppFunction('arma::mat blasso_cpp(arma::mat x) { return x; }',
+                    depends='RcppArmadillo')
R> blasso_cpp(matrix(1:4,2))
     [,1] [,2]
[1,]    1    3
[2,]    2    4
R> 

也許是您RcppArmadillo安裝過程中意外踩踏了一些東西。 也許重新安裝?

另外,您無需分配cppFunction()的結果cppFunction()創建的函數會自動分配給代碼中找到的相同標識符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM