与RcppArmadillo(lapack)链接失败:未定义的符号:dgesdd_

时间:2016-04-19 06:45:31

标签: r rcpp armadillo devtools

我目前正在与RcppArmadillo一起编写R包packageFoo。但是,我在linux中编译我的包有问题。如果有人可以帮助我,我会很高兴。我不知道我做错了什么。

我只有一个带有以下标题的cpp文件:

#include <stdio.h>
#include <string>
#include <bitset>
#include <fstream>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]

using namespace Rcpp;

当我devtools::load_all()时,我得到以下内容:

* installing *source* package ‘packageFoo’ ...
** libs
g++ -I/usr/share/R/include -DNDEBUG   -I"/home/user/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include" -I"/home/user/R/x86_64-pc-linux-gnu-library/3.2/RcppArmadillo/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
g++ -I/usr/share/R/include -DNDEBUG   -I"/home/user/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include" -I"/home/user/R/x86_64-pc-linux-gnu-library/3.2/RcppArmadillo/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c functions.cpp -o functions.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o packageFoo.so RcppExports.o functions.o -L/usr/lib/R/lib -lR
installing to /tmp/Rtmpvf8B08/devtools_install_63383fe5bd9a/packageFoo/libs
* DONE (packageFoo)
Loading required package: Matrix
Error in dyn.load(dllfile) : 
  unable to load shared object '/home/user/Documents/packageFoo/src/packageFoo.so':
  /home/user/Documents/packageFoo/src/packageFoo.so: undefined symbol: dgesdd_

我用Google搜索,发现dgesdd_lapack的一部分。检查与ldd packageFoo.so的{​​{1}}链接并不会显示任何链接的lapack库。

    linux-vdso.so.1 =>  (0x00007ffc3615f000)
    libR.so => /usr/lib/libR.so (0x00007f696e061000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f696dd5d000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f696da57000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f696d841000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f696d47c000)
    libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f696d1ff000)
    libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f696cfb9000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f696cd7b000)
    liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f696cb59000)
    libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f696c949000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f696c730000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f696c528000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f696c324000)
    libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f696c115000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f696bef7000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f696e831000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f696bcce000)

我的MakeVars文件如下所示:

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 

如RcppArmadillo文档中所述。运行R CMD config LAPACK_LIBS会返回-llapack

我正在使用Rcpp_0.12.4RcppArmadillo_0.6.700.3.0devtools_1.11.0

运行R 3.2.5

2 个答案:

答案 0 :(得分:3)

您的包裹或设置与您引用的链接行有问题:

g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro \
        -o packageFoo.so RcppExports.o functions.o \
        -L/usr/lib/R/lib -lR

包含LAPACK / BLAS库。

也许可以通过RcppArmadillo.package.skeleton()从简单包开始并比较?

答案 1 :(得分:2)

问题在于Makevars文件的名称。具体来说,将MakeVars的名称更改为Makevars(Unix / Linux)或Makevars.win(Windows),并确保将其放在src/目录中。