rrcpparmadillodevtools

linking with RcppArmadillo (lapack) fails: undefined symbol: dgesdd_


I am currently writing an R package packageFoo with RcppArmadillo. However, I have problems compiling my package in linux. I would be really glad if someone could help me. I do not know what I do wrong.

I only have a single cpp file with the following header:

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

using namespace Rcpp;

When I do devtools::load_all() I get the following:

* 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_

I googled around and found that dgesdd_ is part of lapack. Checking linking with ldd of packageFoo.so doesn't show any linked lapack libraries.

    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)

My MakeVars file looks like this:

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

as described in the RcppArmadillo documentation. And running R CMD config LAPACK_LIBS returns -llapack

I am running R 3.2.5 with Rcpp_0.12.4, RcppArmadillo_0.6.700.3.0, and devtools_1.11.0


Solution

  • The issue is with the name of the Makevars file. Specifically, change the name of MakeVars to Makevars (Unix / Linux) or Makevars.win (Windows) and make sure it is placed within the src/ directory.