Ask Your Question
0

CMake - Linking external C++ library

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

Phorce gravatar image

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

ngrennan gravatar image

Hello,

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?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

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

Wolf gravatar image

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

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 libmy_lib.so 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

Stats

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

Seen: 6,789 times

Last updated: Feb 06 '14