ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Error linking lapack and blas to armadillo

asked 2022-04-25 01:01:57 -0600

updated 2022-04-25 16:26:11 -0600


I am using ROS2 Foxy for my development project. I am trying to use armadillo library in my code primarily to calculate pseudo inverse of a non-square matrix. I declare the library at the beginning of the code:

include <armadillo>

and also in the Cmakelists of the package for compiling:

find_package(Armadillo REQUIRED)
function(custom_executable subfolder target)
  add_executable(${target} src/${subfolder}/${target}.cpp)
  install(TARGETS ${target}

However, when I try to run the pinv function to calculate the pseudo inverse, the following linking errors pops up highlighting that lapack and blas are not linked to Armadillo:

undefined reference to 'wrapper2_dgetrs_' 
undefined reference to 'wrapper2_dgecon_' etc.

These are just a few errors I have listed. There are more errors which indicate that lapack and blas library are not linked to Armadillo. Please help me solve this error. There should be a way to link the libraries to Armadillo in the Cmakelists...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-04-25 18:47:00 -0600

aprotyas gravatar image

It seems that the -llapack and -lblas linking options are not implicit. In addition to what you have, you may want to find and link against those imported targets too:

find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
target_link_libraries(${target} PRIVATE BLAS::BLAS LAPACK::LAPACK)
edit flag offensive delete link more


Thanks @aprotyas for your quick reply. I have included the packages as you mentioned. But for linking the libraries to Armadillo specifically, I have to add Armadillo library along with its path using:

add_library(Armadillo /path/to/Armadillo/library)

and then link libraries BLAS and LAPACK to it. Unfortunately that overwrites find_package(Armadillo REQUIRED) and breaks the link to some parts of the Armadillo library.

I have checked the headers: #define ARMA_USE_LAPACK and #define ARMA_USE_BLAS are already uncommented in the config.hpp file of armadillo_bits. So as per my understanding Armadillo should already be using BLAS and LAPACK installed.

However, the error persists. And I am still stuck on the fact that Armadillo is not linked to the BLAS AND LAPACK during compiling at least.

karanjotsingh010 gravatar image karanjotsingh010  ( 2022-04-26 03:44:22 -0600 )edit

Question Tools

1 follower


Asked: 2022-04-24 22:41:54 -0600

Seen: 245 times

Last updated: Apr 25 '22