Undefined Reference to LAPACK wrapper of Armadillo

user2477647 picture user2477647 · Jun 12, 2013 · Viewed 8.8k times · Source

I have a question regarding the use of Armadillo.

I'm using Ubuntu 12.10, and the gcc compiler in Code::Blocks. I installed LAPACK and BLAS using the synaptic package manager. I also installed Armadillo once using the synaptic package manager, once by hand with CMake. CMake found the LAPACK and BLAS libraries while making the configurations for the armadillo compilation. Furthermore, I linked the libraries of BLAS and LAPACK in Code::Blocks in 'Build Options"->"Linker'`.

However, whenever I want to build my project, I get the error message:

 In function `void arma::lapack::getrf<double>(int*, int*, double*, int*, int*, int*)':|
/usr/include/armadillo_bits/lapack_wrapper.hpp|41|undefined reference to `wrapper_dgetrf_'|

It obviously means that armadillo cannot find LAPACK, but what did I do wrong?

I also discommented the respective lines in the armadillo_bits/config.hpp file, so that it looks like this:

    #if !defined(ARMA_USE_LAPACK)
    //#define ARMA_USE_LAPACK
    //// Uncomment the above line if you have LAPACK or a high-speed replacement for LAPACK,
    //// such as Intel MKL, AMD ACML, or the Accelerate framework.
    //// LAPACK is required for matrix decompositions (eg. SVD) and matrix inverse.
    #endif

    #if !defined(ARMA_USE_BLAS)
    //#define ARMA_USE_BLAS
    //// Uncomment the above line if you have BLAS or a high-speed replacement for BLAS,
    //// such as OpenBLAS, GotoBLAS, Intel MKL, AMD ACML, or the Accelerate framework.
    //// BLAS is used for matrix multiplication.
    //// Without BLAS, matrix multiplication will still work, but might be slower.
    #endif

    /* #undef ARMA_USE_WRAPPER */
    //// Comment out the above line if you're getting linking errors when compiling your programs,
    //// or if you prefer to directly link with LAPACK and/or BLAS.
    //// You will then need to link your programs directly with -llapack -lblas instead of -larmadillo

The error appears first when I try to set up a matrix with integers, so

  Mat<int> element_nodes;

I would appreciate helpful answers. I did search the internet for a couple of hours. Also, if you need more source code, let me know.

Answer

mtall picture mtall · Jun 13, 2013

Looks like you have two copies of Armadillo installed, which have different configurations. If in doubt, link your programs with:

g++ prog.cpp -o prog -O2 -larmadillo -llapack -lblas

You may also want to have a look at Armadillo's FAQ and a previous Stackoverflow question.