Robotics StackExchange | Archived questions

how to include path to external libraries used by nodes?

Hi,

I have created a function in C++11 that uses Armadillo linear algebra library. If I have to comile the code from terminal successfully, I use the following line

g++ -std=c++11 -I/home/myname/armadillo/include mycode.cpp mycode.o -llapack -lblas

Now I want to use the same code as a ROS publisher node. For that I have created a ROS package and copied mycode.cpp file inside the src folder of the package that I have created. Then I add addcompileoptions(-std=c++11) to the CMakeLists.txt file. Next I do catkin_make to build ROS workspace with the newly created package. And I receive the following error

error: could not convert ‘{-9.8e-1, 1.4e-1, 3.6e-2, {1.4e-1, 9.8e-1, -6.5e-2}, {-1.1e+0}}’ from ‘<brace-enclosed initializer list>’ to ‘arma::mat {aka arma::Mat<double>}’

I understand the error is because Armadillo library. In my view I need to show the path /home/myname/armadillo/include somewhere inside the CMakeLists.txt file but not sure how to do that. It would be very helpful if somebody help me on the problem?

Thank you in advance.

Asked by anirban on 2018-11-29 18:02:35 UTC

Comments

Answers

You should add the path directly to the include_directories entry as shown below. this should be just before the executable definitions for the binaries.

include_directories(include
  ${catkin_INCLUDE_DIRS}
  /your/custom/include/path/here
)

Update:

I've just had another look at this and I don't think the error is caused by the lack of include files. You should enable c++11 in CMakeLists.txt as shown below, I think the compiler version is still wrong which is causing it to fail at the first c++11 only feature in the code.

# Enable c++11 compiler
add_definitions(-std=c++11)

Asked by PeteBlackerThe3rd on 2018-11-29 18:57:42 UTC

Comments

After adding the custom path to the include_directories as you mentioned, I still get the same error during catkin_make. Any idea about how will I link LAPACK and BLAS libraries? While I compile the code from terminal wothput ROS I use -llapack and -lblas.

Asked by anirban on 2018-11-29 21:18:08 UTC

I've had another look at this error and updated my answer.

Asked by PeteBlackerThe3rd on 2018-11-30 02:21:33 UTC

Can you try :

find_package(BLAS)
find_package(LAPACK)

target_link_libraries(<your_node> ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} <other libs>)

Asked by tuandl on 2018-11-30 06:16:37 UTC

I tried what @tuandl and @PeteBlackerThe3rd has mentioned but unfortunately same error appears

Asked by anirban on 2018-11-30 18:01:54 UTC

Do you have:

link_directories(
    include
    ${BLAS_LIBRARY_DIRS}
    ${LAPACK_LIBRARY_DIRS}
)

Asked by tuandl on 2018-12-01 03:16:03 UTC

@tuandl I have link_directories specified as you showed. But the same error persists.

Asked by anirban on 2018-12-07 22:53:16 UTC