ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

cannot find libraries when linking

asked 2011-03-08 02:57:03 -0500

tomurillo gravatar image

updated 2011-03-08 03:24:49 -0500

Tully gravatar image

Hi, I find the following error message when trying to compile my code, by using the "make" command. All the required libraries (.so and .a) are in the /lib folder of my project source directory. What am I doing wrong?

Error message:

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

The contents of my CMakeLists file are:

cmake_minimum_required(VERSION 2.4.6)



rosbuild_add_executable(basic_soar_test example/basic_soar_test.cpp)
target_link_libraries(basic_soar_test ElementXML ConnectionSML SoarKernelSML ClientSML)

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-03-08 06:13:42 -0500

dornhege gravatar image

You need to set the link directory to where the libraries are using link_directories(dir).

edit flag offensive delete link more


How do you do the above?

gowtham gravatar image gowtham  ( 2013-10-02 08:02:51 -0500 )edit


dornhege gravatar image dornhege  ( 2013-10-02 08:16:29 -0500 )edit

@dornhege Hi,I am a complete beginner in ROS. Can you please explain in detail how to "set the link directory to where the libraries are using link_directories(dir)"?Thanks in advance

gowtham gravatar image gowtham  ( 2013-10-03 04:41:06 -0500 )edit

This is literally the command to use in CMakeLists.txt, just replace dir by the directory that you need to set.

dornhege gravatar image dornhege  ( 2013-10-03 06:12:39 -0500 )edit

I have the same issue, but I did put "link_directories(/usr/local/lib)" where i copied my *.so file. When I try to make my pkg on a different machine I get the same error. Why?

zweistein gravatar image zweistein  ( 2013-12-16 21:58:00 -0500 )edit

Probably because the library is not there? If the library is build with ROS there are other possibilities to link.

dornhege gravatar image dornhege  ( 2013-12-16 22:40:44 -0500 )edit

My lib is there, i copied and verified it. But i still get the error. It is not a ROS lib, but an external one, related to OpenCV.Update: the lib path was /usr/local/lib. This works on my PC but on an other one doesn't. But on the other PC if I set the lib path to: source_project_dir/src and copy my lib there, than it Works, WHY?

zweistein gravatar image zweistein  ( 2013-12-17 00:13:58 -0500 )edit

This doesn't seem like exactly the same problem, so please open a new question and include all exact path for all libraries you need + the CMakeLists.txt and any error messages.

dornhege gravatar image dornhege  ( 2013-12-17 02:40:48 -0500 )edit

Question Tools

1 follower


Asked: 2011-03-08 02:57:03 -0500

Seen: 7,261 times

Last updated: Mar 08 '11