Rosanswers logo

I am using rosrun to run my program that successfully compiles. The program links to another shared object library.

  1. If I run it inside the bin/ directory where my executable is using rosrun, it works fine. I use the command:

rosrun MYPROGRAM myprogram

  1. If I manually run my ROS node without rosrun ( ./myprogram) it also works fine.

  2. If I navigate to any other directory on the system (for example, my ROS workspace) and run

rosrun MYPROGRAM myprogram

I get an error that the shared object library cant be found. Also, running

ldd myprogram

does show the correct linkage on the shared object library. Can anyone enlighten me on the reason why this happens?


update: The shared object library is linked to in the CMakeLists file by a relative directory using


and this library is not located in any kind of system link path.

Update2: It seems the reason is that executables are run from your current directory, and since I linked relative and I try to rosrun from somewhere else, it cant find the relative library. This behavior is apparently different on other systems, and with some compilers it defaults to getting the absolute path when a relative path is given. To make it a little more portable, I used the following cmake directive:


and then made sure to use ${LIBBASEDIR} in my link_directories.

I would still appreciate any comments anyone may have on this...

Originally posted by PerkinsJames on ROS Answers with karma: 506 on 2012-10-02

Post score: 0


1 Answer 1


Rosanswers logo

Perhaps some of the ROS CMake examples will help you figure out what to do.

If not, please update your question with the exact contents of your CMakeLists.txt.

Originally posted by joq with karma: 25443 on 2012-10-02

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

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