R(macos 10.8.5),RcppArmadillo:找不到犰狳库或符号_wrapper_ddot_

R (macos 10.8.5), RcppArmadillo : can not find armadillo library or symbol _wrapper_ddot_

安装 "RcppArmadillo" 使我非常失败,现在已经有几个小时了,在 "R"

R-2.3.1

和MACOS系统10.8.5:

Darwin 12.6.0 Darwin Kernel Version 12.6.0; xnu/RELEASE_X86_64 x86_64

Armadillo (6.100.0)编译安装成功

这是违规者:

R> install.packages("RcppArmadillo", verbose=T)

编译正常但未能成功加载包(作为构建时测试)。输出是这样的:

* 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
g++ -I/opt/local/R.framework/Resources/include -DNDEBUG  -arch x86_64 -framework System -Wunused-command-line-argument-hard-error-in-future -I/opt/local/include -I/Users/.../usr/include -I/Users/.../usr/local/include -I/opt/X11/include -Wunused-command-line-argument-hard-error-in-future -I"/opt/local/R.framework/Versions/3.2/Resources/library/Rcpp/include"  -I../inst/include -fPIC  -arch x86_64 -framework System -Wunused-command-line-argument-hard-error-in-future -I/opt/local/include -I/Users/.../usr/include -I/Users/.../usr/local/include -I/opt/X11/include -Wunused-command-line-argument-hard-error-in-future  -c RcppArmadillo.cpp -o RcppArmadillo.o
clang: warning: -framework System: 'linker' input unused
clang: warning: -framework System: 'linker' input unused
g++ -I/opt/local/R.framework/Resources/include -DNDEBUG  -arch x86_64 -framework System -Wunused-command-line-argument-hard-error-in-future -I/opt/local/include -I/Users/.../usr/include -I/Users/.../usr/local/include -I/opt/X11/include -Wunused-command-line-argument-hard-error-in-future -I"/opt/local/R.framework/Versions/3.2/Resources/library/Rcpp/include"  -I../inst/include -fPIC  -arch x86_64 -framework System -Wunused-command-line-argument-hard-error-in-future -I/opt/local/include -I/Users/.../usr/include -I/Users/.../usr/local/include -I/opt/X11/include -Wunused-command-line-argument-hard-error-in-future  -c RcppExports.cpp -o RcppExports.o
clang: warning: -framework System: 'linker' input unused
clang: warning: -framework System: 'linker' input unused
g++ -I/opt/local/R.framework/Resources/include -DNDEBUG  -arch x86_64 -framework System -Wunused-command-line-argument-hard-error-in-future -I/opt/local/include -I/Users/.../usr/include -I/Users/.../usr/local/include -I/opt/X11/include -Wunused-command-line-argument-hard-error-in-future -I"/opt/local/R.framework/Versions/3.2/Resources/library/Rcpp/include"  -I../inst/include -fPIC  -arch x86_64 -framework System -Wunused-command-line-argument-hard-error-in-future -I/opt/local/include -I/Users/.../usr/include -I/Users/.../usr/local/include -I/opt/X11/include -Wunused-command-line-argument-hard-error-in-future  -c fastLm.cpp -o fastLm.o
clang: warning: -framework System: 'linker' input unused
clang: warning: -framework System: 'linker' input unused
g++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/opt/local/R.framework/Resources/lib -arch x86_64 -framework System -Wunused-command-line-argument-hard-error-in-future -L/opt/local/lib -L/Users/.../usr/lib -L/Users/.../usr/lib -L/opt/X11/lib -o RcppArmadillo.so RcppArmadillo.o RcppExports.o fastLm.o -L/opt/local/R.framework/Resources/lib -lRlapack -L/opt/local/R.framework/Resources/lib -lRblas -F/opt/local/R.framework/.. -framework R -lintl -Wl,-framework -Wl,CoreFoundation
installing to /opt/local/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 '/opt/local/R.framework/Versions/3.2/Resources/library/RcppArmadillo/libs/RcppArmadillo.so':
  dlopen(/opt/local/R.framework/Versions/3.2/Resources/library/RcppArmadillo/libs/RcppArmadillo.so, 6): Symbol not found: _wrapper_ddot_
  Referenced from: /opt/local/R.framework/Versions/3.2/Resources/library/RcppArmadillo/libs/RcppArmadillo.so
  Expected in: flat namespace
 in /opt/local/R.framework/Versions/3.2/Resources/library/RcppArmadillo/libs/RcppArmadillo.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/opt/local/R.framework/Versions/3.2/Resources/library/RcppArmadillo’

所以,简而言之,它需要找不到符号“_wrapper_ddot_”。 但是这个符号在已经安装成功的/opt/local/lib/libarmadillo.6.dylib中。例如:

命令:

nm /opt/local/lib/libarmadillo.6.dylib | grep _wrapper_ddot_

输出:

/opt/local/lib/libarmadillo.6.dylib
00000000000023e0 T _wrapper_ddot_

然后我创建一个 ~/.R/Makevars 来包含:

PKG_LIBS += -L/opt/local/lib -larmadillo

尝试重新安装使用:

R> install.packages("RcppArmadillo")

再次编译正常,但现在无法加载犰狳 dylib 并给出此错误消息:

...
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/private/tmp/RtmpqEsodh/Rinst62b64deb7e7/RcppArmadillo/libs/RcppArmadillo.so':
  dlopen(/private/tmp/RtmpqEsodh/Rinst62b64deb7e7/RcppArmadillo/libs/RcppArmadillo.so, 6): Library not loaded: libarmadillo.6.dylib
  Referenced from: /private/tmp/RtmpqEsodh/Rinst62b64deb7e7/RcppArmadillo/libs/RcppArmadillo.so
  Reason: image not found
Error: loading failed

我什至跳过测试然后安装手动编译包。不!它总是抱怨它无法加载犰狳库或找不到符号“_wrapper_ddot_”

然而,(依赖)犰狳库在那里:

ls -al /opt/local/lib/libarmadillo.6.10.0.dylib

-rwxr-xr-x  1 root  admin  5... /opt/local/lib/libarmadillo.6.10.0.dylib

(以及指向它的各种符号链接,例如 6.dylib 和 dylib)

将 ~/.R/Makevars 设置为:

PKG_LIBS += -larmadillo
CFLAGS += ${PKG_LIBS}
CXXFLAGS += ${PKG_LIBS}

这方面没有带来任何好消息(我现在很绝望)。

最后,我编写了一个小的 c 程序来 dlopen() 犰狳库 (dylib)。根据我使用的打开模式,它成功或失败如下:

trying : mode 2 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 2 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 1 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 1 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 8 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 8 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 4 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 4 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 18 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    error for mode 18 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'    err: Undefined error: 0
trying : mode 17 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    error for mode 17 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'    err: Undefined error: 0
trying : mode 24 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    error for mode 24 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'    err: Undefined error: 0
trying : mode 20 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    error for mode 20 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'    err: Undefined error: 0
trying : mode 130 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 130 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 129 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 129 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 136 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 136 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 132 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 132 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 258 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 258 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 257 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 257 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 264 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 264 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
trying : mode 260 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'
    success: mode 260 and lib '/opt/local/lib/libarmadillo.6.10.0.dylib'

使用各种模式测试加载犰狳库的 C 程序是:

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <dlfcn.h>

int main(void){
    char lib[] = "/opt/local/lib/libarmadillo.6.10.0.dylib";
    int modes[] = {
        RTLD_NOW, RTLD_LAZY, RTLD_GLOBAL, RTLD_LOCAL,
        RTLD_NOW|RTLD_NOLOAD, RTLD_LAZY|RTLD_NOLOAD, RTLD_GLOBAL|RTLD_NOLOAD, RTLD_LOCAL|RTLD_NOLOAD,
        RTLD_NOW|RTLD_NODELETE, RTLD_LAZY|RTLD_NODELETE, RTLD_GLOBAL|RTLD_NODELETE, RTLD_LOCAL|RTLD_NODELETE,
        RTLD_NOW|RTLD_FIRST, RTLD_LAZY|RTLD_FIRST, RTLD_GLOBAL|RTLD_FIRST, RTLD_LOCAL|RTLD_FIRST
    };


    for(int modeI=0;modeI<16;modeI++){
        int mode = modes[modeI];
        void    *ahandle;
        printf("trying : mode %d and lib '%s'\n", mode, lib);
        if( (ahandle=dlopen(lib, mode)) == NULL ){
            fprintf(stderr, "\terror for mode %d and lib '%s'", mode, lib);
            printf("\terr: %s\n", strerror(errno));
        } else {
            dlclose(ahandle);
            printf("\tsuccess: mode %d and lib '%s'\n", mode, lib);
        }
    }
}

问题: 为什么 R 不加载犰狳库? 有没有等价于LD_LIBRARY_PATH的R?

安装的其他包工作正常(大约 30 个包)。

另外,犰狳C++程序编译运行正常:

#include <iostream>
#include <armadillo>

using namespace std;
using namespace arma;

int main(int argc, char** argv)
  {
  mat A = randu<mat>(4,5);
  mat B = randu<mat>(4,5);

  cout << A*trans(B) << endl;

  return 0;
  }

g++ -I/opt/local/include -L/opt/local/lib arma.c -larmadillo

非常感谢,

请注意,RcppArmadillo 捆绑了 Armadillo(它是一个 header-only 库),因此使用 RcppArmadillo.h 的客户端包将获得它们在编译时需要的 armadillo 部分——显式链接到pre-compiled armadillo 库应该是不必要的。

RcppArmadillo 确实在某些编译代码(例如 fastLm)中使用了 armadillo 的片段(来自它自己包含的 headers),这些应该在 RcppArmadillo自己的共享object文件,RcppArmadillo.so.

在我的 OS X (El Capitan) 机器上,我看到 ddot 符号上没有 wrapper 前缀:

kevin:~/Library/R/3.2/library/RcppArmadillo/libs
$ nm RcppArmadillo.so | grep ddot
                 U _ddot_

有一个#defineARMA_USE_WRAPPER似乎控制了这个。选择的导出名称配置在:

https://github.com/RcppCore/RcppArmadillo/blob/master/inst/include/armadillo_bits/config.hpp#L46-L49

并在这里使用:

https://github.com/RcppCore/RcppArmadillo/blob/master/inst/include/armadillo_bits/compiler_setup.hpp#L51-L57

我认为您需要确保未设置 #define。您是否可以在其他地方设置/配置它?

2 1/2 年后问题再次出现,解决方案仍然有效且相关。 OSX 中的 R-3.4.3 拒绝安装该死的 RcppArmadillo,除非我先通过 port uninstall armadillo 删除犰狳系统包(不是 R 包)。

所以,

port uninstall armadillo

兄弟