ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

CMake - Linking external C++ library

asked 2014-02-06 09:43:53 -0600

Phorce gravatar image

updated 2016-10-24 08:35:49 -0600

ngrennan gravatar image


I have an external .cpp library that requires both the following libraries: atlas, llpack and lblas

Now if for example, I compile using terminal (on the same machine) I can use the following:

g++ main.cpp hmm.cpp -I /usr/include/atlas -L /usr/lib64/atlas/ -llapack -lblas

This will work. I don't know how to include these libraries into the CMake list in ROS. I have, currently, the following:

rosbuild_add_executable(build1 src/hmm.c)

What would I have to add into my CMake list to make this work?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-02-06 19:21:48 -0600

Wolf gravatar image

updated 2014-02-06 23:42:49 -0600

link_directories( /usr/lib64/atlas )

equivalent to -L /usr/lib64/atlas of gcc/g++

And after :

rosbuild_add_executable(build1 src/hmm.c)

you put

target_link_libraries( build1 lapack blas )

equivalent to -llapack -lblas

Note: First arg of target_link_libraries is the previously defined target to link.

Note: no prepended -l in target_link_libraries, i e. if your external lib is named you just add my_lib to target_link_libraries

edit flag offensive delete link more

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


Asked: 2014-02-06 09:43:53 -0600

Seen: 6,979 times

Last updated: Feb 06 '14