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

error while loading shared libraries

asked 2017-10-03 08:26:27 -0500

Chrizzl gravatar image

updated 2017-10-03 08:52:17 -0500

I want to use shared objects as libraries. The .so files of them are at my disposal.

I created a catkin_package. That package contains a source, include and lib folder (where I put the .so files)

My CMakeLists.txt of the package is the following:

cmake_minimum_required(VERSION 2.8.3)
project(yocto3d)

find_package(catkin REQUIRED COMPONENTS)

catkin_package()

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(yocto3d src/main.cpp)
target_link_libraries(yocto3d ${catkin_LIBRARIES} ${PROJECT_SOURCE_DIR}/lib/libyapi.so.1.0.1 ${PROJECT_SOURCE_DIR}/lib/libyocto.so.1.0.1)

Everything compiles without warnings and errors, but when I run

rosrun yocto3d yocto3d

I get the following error (can't find the libraries)

 /home/dh/catkin_ws/devel/lib/yocto3d/yocto3d: error while loading shared libraries: libyocto.so.1.0.1: cannot open shared object file: No such file or directory

What am I missing?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-10-04 02:16:24 -0500

Chrizzl gravatar image

updated 2017-10-04 02:58:15 -0500

I copied the two libraries (.so files) to /usr/lib. When running the program the files in this folder will be used, when compiling with catkin_make the files in catkin_ws/src/yocto3d/lib will be used.

In conclusion: the paths to the libraries are different when compiling and when running the program.

edit flag offensive delete link more

Comments

1

As far as I can tell, #q203315 does not suggest adding lib to your include_directories(..) statement at all. Libraries are not headers, so I also don't really understand how adding that directory to your include path would help here.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 02:18:32 -0500 )edit

It probably has to do with the fact that my .so libraries are located inside /lib of my project folder? Maybe rosrun wouldn't look inside that folder at runtime? I don't know exactly why it works either.

Chrizzl gravatar image Chrizzl  ( 2017-10-04 02:25:38 -0500 )edit

include_directories(..) changes the include path, for headers. That is a compile time construct, not something that is used at runtime when loading libraries.

And rosrun is not involved here: your OS (or more precisely: the ELF loader) is complaining it can't find the libs, not ROS.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 02:30:29 -0500 )edit

I found out I did one more thing to fix this problem, will edit my answer.

Chrizzl gravatar image Chrizzl  ( 2017-10-04 02:39:19 -0500 )edit

Btw: very nice that you're reporting back about this. If my comments come across as dismissive, don't interprete them that way. I'm just really surprised that adding lib to your include path changes anything here.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 02:42:39 -0500 )edit

I think you will understand it now, when you look at my updated answer. I copied the libraries to the runtime location.

Chrizzl gravatar image Chrizzl  ( 2017-10-04 02:52:07 -0500 )edit
2

I also copied the two libraries (.so files) to /usr/lib

ok. That is what made things work. The change to your include path is unnecessary.

/usr/lib is by default searched by your system's binary loader for libraries, so that makes sense.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 02:54:43 -0500 )edit

Try to remove the change you made to the include_directories(..) statement. It should still work.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 02:56:23 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-10-03 08:26:27 -0500

Seen: 6,140 times

Last updated: Oct 04 '17