gpt4 book ai didi

r - Rcpp 错误中的 cppFunction

转载 作者:行者123 更新时间:2023-11-28 02:18:51 25 4
gpt4 key购买 nike

大约 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。这是我的 session 信息。

> 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() 的结果——创建的函数会自动分配给在代码中找到的相同标识符。

关于r - Rcpp 错误中的 cppFunction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33201837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com