Getting the local_setup script to put install/lib into LD_LIBRARY_PATH for custom app

319 views
Skip to first unread message

Brad Baillio

unread,
May 3, 2016, 7:56:28 PM5/3/16
to ROS SIG NG ROS
Building a custom app, and I am creating some .so files. I can move them to the lib directory using the cmake command:

install(TARGETS library_name LIBRARY DESTINATION lib)

But that doesn't get the setup scripts to point to that dir automatically. (Let's assume there nothing else going in there).
So if I try to run my executable, it can't find the needed shared libs.

Suggestions?
Thanks.

Dirk Thomas

unread,
May 3, 2016, 8:22:37 PM5/3/16
to ROS SIG NG ROS
You might want to share more information about what exactly you do and how your code looks like. Otherwise others can only make assumptions and guess what might be the case and their answers might not be of much help.

Since you mention LD_LIBRARY_PATH I assume you are not using Windows or OS X but Linux.

Every CMake package which is being built by `ament build` should have the necessary environment hook to contribute to the library path (https://github.com/ament/ament_tools/blob/master/ament_tools/build_types/cmake.py#L278-L280).

Maybe you have not sourced the resulting install(_isolated)/local_setup.bash file after building the workspace?

Cheers,
- Dirk


--
You received this message because you are subscribed to the Google Groups "ROS SIG NG ROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ros-sig-ng-ro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brad Baillio

unread,
May 4, 2016, 10:52:21 AM5/4/16
to ROS SIG NG ROS
Specifically, I'm building a shared library using the ament build system on Ubuntu 14.04.
I can get my packages.xml and CMakeLists.txt to compile the shared library just fine.
Everything compiles cleanly, and if I add the install() cmake line, my shared library gets copied from the build directory into whatever directory I specify (in this case install/lib).
If I source the local_setup.bash file, it does not add install/lib to LD_LIBRARY_PATH.
It will add install/bin to the PATH, even though that directory doesn't exist.

The only notable difference in my Shared library project's CMakeLists.txt file is that I'm not making the call to call_for_each_rmw_implementation(), because it doesn't like making multiple versions of a shared library.
Is it possible that's where my problem is?
Will there be bad repercussions from not making that cmake call, when it comes time to use/link my shared library? (the shared library does have a publisher, node, etc).

I can manually work around the issue, but it would be nice if the install/lib directory made it into the local_setup.bash file.

Thanks.

Dirk Thomas

unread,
May 4, 2016, 5:49:47 PM5/4/16
to ROS SIG NG ROS
The CMake function `call_for_each_rmw_implementation` is only useful if you want to build targets against multiple RMW implementations. Common user packages won't need to do that since they will just build against the default RMW implementation. We use this mostly for testing and demonstrating cross-vendor compatibility. Since you are building a ROS agnostic library the usage the function wouldn't make any sense anyway.

If you can share a minimal reproducible example I could give it a try.

Cheers,
- Dirk

Brad Baillio

unread,
May 4, 2016, 5:58:07 PM5/4/16
to ROS SIG NG ROS
I created a Gazebo (7) plugin that simulates a velodyne at a really slow spin rate.
As part of the plugin, I output the gazebo::LaserScanStamped data as sensor_msgs::msg::PointCloud2 data.
I'm publishing on a ROS2 topic.

So I can build the plugin just fine, and it's fully operational. I can attach rviz, via the dynamic_bridge, and see the PointCould2 data.
But the local_setup.bash script only sticks the install/bin directory into my path.
I figured there's some magic in the ament build process that should inform that I've copied things into install/lib directory, but that doesn't seem to be happening.
In other projects I am working with, there are msg.so type files that get placed in lib, and those projects add the install/lib dir to LD_LIBRARY_PATH when calling the local_seutp.bash file.

Anyways, I've got a workaround for now so it's not holding me up.

I'll work on a minimal reproducible example that illustrates my dilemma.

Bob Dean

unread,
May 6, 2016, 1:34:50 PM5/6/16
to ros-sig...@googlegroups.com
I think brad is asking how to add a custom lib oath to the environment setup scripts

Sent from my iPhone

Dirk Thomas

unread,
May 6, 2016, 2:03:23 PM5/6/16
to ROS SIG NG ROS
Without seeing any code I can only guess that your CMake file is not exporting the library correctly.

An exported library needs to:

* be listed in the `<pkgname>_LIBRARIES` variable after `find_package(<pkgname>)` is called and
* create an environment hook to set e.g. `LD_LIBRARY_PATH` (platform dependent) when the package setup file is sourced

Did you call `ament_export_libraries()` in your CMake file? If yes, ament_cmake will do both steps for you automatically. If no, you need to extend the CMake config file to add your lib to `<pkgname>_LIBRARIES` and create the environment hook file manually.

Cheers
- Dirk


Brad Baillio

unread,
May 13, 2016, 2:54:47 PM5/13/16
to ROS SIG NG ROS
Thanks. The ament_export_libraries() did the trick.
Reply all
Reply to author
Forward
0 new messages