Ask Your Question
0

how to include path to external libraries used by nodes?

asked 2018-11-29 17:02:35 -0500

anirban gravatar image

updated 2018-11-29 20:41:58 -0500

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 add_compile_options(-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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-11-29 17:57:42 -0500

updated 2018-11-30 01:17:52 -0500

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)
edit flag offensive delete link more

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.

anirban gravatar image anirban  ( 2018-11-29 20:18:08 -0500 )edit

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

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-30 01:21:33 -0500 )edit

Can you try :

find_package(BLAS)
find_package(LAPACK)

target_link_libraries(<your_node> ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} <other libs>)
tuandl gravatar image tuandl  ( 2018-11-30 05:16:37 -0500 )edit

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

anirban gravatar image anirban  ( 2018-11-30 17:01:54 -0500 )edit

Do you have:

link_directories(
    include
    ${BLAS_LIBRARY_DIRS}
    ${LAPACK_LIBRARY_DIRS}
)
tuandl gravatar image tuandl  ( 2018-12-01 02:16:03 -0500 )edit

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

anirban gravatar image anirban  ( 2018-12-07 21:53:16 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-11-29 17:02:35 -0500

Seen: 67 times

Last updated: Nov 30 '18