0
$\begingroup$

Rosanswers logo

Hi,

(excuse my english)

I am a new with ROS, I am trying to build a node for a driver, the problem is that I need to use an externe library that does the communication staff, how can tell the compiler to use this library in CMakeLists ? normally if I want to use this library I will do:

g++ -g -Wall main_foo.cpp other.cpp lib/dmclnx.a -Idmclnxlib -o run_foo

I have already read the tutorial for CMakeLists and Manifest . Thanks for help.


Originally posted by Anas on ROS Answers with karma: 126 on 2011-07-09

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Let's say you have a library called libfoo located in /usr/local/lib and you want to link it with a node you're building called my_node. Put the following in your CMakeLists.txt:

# set the path to the library folder
link_directories(/usr/local/lib)

# link the libraries to the executable
target_link_libraries (my_node foo)

(/usr/local/lib is probably in your environment path already, so the first line might be unnecessary)


Originally posted by Ivan Dryanovski with karma: 4954 on 2011-07-09

This answer was ACCEPTED on the original site

Post score: 11


Original comments

Comment by zweistein on 2013-11-25:
I included the lines suggested above and generated the RailwayImageProcess.so lib in /usr/local/lib: target_link_libraries(railDetect RailwayImageProcess) rosbuild_add_executable(railDetect src/main.cpp)

but i get this error for make . :

CLinking CXX executable bin/railDetect /usr/bin/ld: cannot find -lRailwayImageProcess collect2: ld returned 1 exit status make[2]: *** [bin/railDetect] Error 1 make[1]: *** [CMakeFiles/railDetect.dir/all] Error 2 make: *** [all] Error 2

Comment by bergercookie on 2016-04-05:
I think you first have to issue the add_executable directive and then link against any libraries.

Comment by bergercookie on 2016-04-05:
Also, including the prefix (lib) or the suffix (.so/.a/.la) doesn't affect the link_directories or target_link_libraries commands.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.