Repository navigation
Closed
Labels
invalidThis doesn't seem right
Description
Hi, hopefully this is the right place to ask this - I've been trying to create a statically linked package via rclcpp, but whenever I run the command colcon build --cmake-args -DBUILD_SHARED_LIBS=OFF on the examples project (https://github.com/ros2/examples), I get:
...
Finished <<< examples_rclcpp_minimal_subscriber [12.3s]
--- stderr: examples_rclcpp_minimal_timer
CMake Warning:
Manually-specified variables were not used by the project:
BUILD_SHARED_LIBS
...
Summary: 13 packages finished [25.9s]
7 packages had stderr output: examples_rclcpp_minimal_action_client examples_rclcpp_minimal_action_server examples_rclcpp_minimal_client examples_rclcpp_minimal_publisher examples_rclcpp_minimal_service examples_rclcpp_minimal_subscriber examples_rclcpp_minimal_timer
If I attempt to run the executable in the /install/examples_rclcpp_minimal_publisher/lib/examples_rclcpp_minimal_publisher, in a fresh terminal (without sourcing the setup.bash file) I'll get an error stating:
./publisher_member_function: error while loading shared libraries: librclcpp.so: cannot open shared object file: No such file or directory
Which (I think) confirms that the arg was ignored.
Am I missing something?
Ubuntu 18.04 LTS
cmake version 3.10.2
colcon version-check:
colcon-argcomplete 0.2.2: newer version available (0.2.3)
colcon-bash 0.3.1: up-to-date
colcon-cmake 0.2.4: up-to-date
colcon-core 0.3.14: up-to-date
colcon-defaults 0.2.1: up-to-date
colcon-devtools 0.2.1: up-to-date
colcon-library-path 0.2.0: up-to-date
colcon-metadata 0.2.1: up-to-date
colcon-notification 0.2.5: up-to-date
colcon-output 0.2.3: up-to-date
colcon-package-information 0.2.1: up-to-date
colcon-package-selection 0.2.1: up-to-date
colcon-parallel-executor 0.2.2: up-to-date
colcon-pkg-config 0.1.0: up-to-date
colcon-powershell 0.3.3: up-to-date
colcon-python-setup-py 0.2.1: up-to-date
colcon-recursive-crawl 0.2.0: up-to-date
colcon-ros 0.3.5: up-to-date
colcon-test-result 0.3.0: up-to-date
colcon-zsh 0.3.1: up-to-date
Metadata
Metadata
Assignees
Labels
invalidThis doesn't seem right
Activity
dirk-thomas commentedon Dec 26, 2018
The warning in
examples_rclcpp_minimal_subscribercomes from the fact that the package doesn't declare that CMake option. The option is being defined in the ament_cmake_ros package which the example package doesn't use (since it doesn't build a library it doesn't have to). You can suppress the warning by passing the CMake argument--no-warn-unused-cli.From your description it isn't clear what packages you built in your workspace - only that contains 13 packages. Also you mention that you ran the example "without sourcing the setup.bash file". Shared libraries can't be found when the environment variable
LD_LIBRARY_PATHisn't defined so that would explain why the example fails to load the shared library.In order to help you please provide complete steps to reproduce your issues.
eeyang92 commentedon Dec 27, 2018
I want to be able to compile the example repository, and be able to run the output binaries anywhere (even on a different system - with the same architecture). This would require me to statically link the libraries, so
--no-warn-unused-cliwouldn't work for me.Or is this not possible and I should just include the shared libraries in my packages, even on a different system?
dirk-thomas commentedon Dec 27, 2018
The package
examples_rclcpp_minimal_subscriberdoesn't build any libraries therefore theBUILD_SHARED_LIBSoptions doesn't do anything for it. That is the reason for the warning and you can suppress it with the mentioned CMake argument (or you can just ignore thestderroutput).In order to build the example without depending on any shared library you have to build the packages which provide these libraries with the
BUILD_SHARED_LIBSoption, e.g.rcutils,rcl,rclcpp, etc. That is why I mentioned the number of packages in your workspace. I suspect that you are not trying to build all the dependency packages yourself.It is possible to build the packages with static libraries - you just have to actually build all packages which do contain libraries. Or you make sure that the shared libraries are available on the target system and findable via
LD_LIBRARY_PATH( I assume you are not aiming for a different architecture here, so no cross compiling is necessary).As mentioned before:
eeyang92 commentedon Dec 27, 2018
Original replication steps:
colcon build --symlink-install. ./ros2_dir/install/setup.bashcolcon build, alsocolcon build --cmake-args -DBUILD_SHARED_LIBS=OFFAfter reading your message, it seems like I also need to build the entirety of
ros2statically? At least the ones you mentioned (i.e.rcutils).I then tried:
ros2from source, withcolcon build --cmake-args -DBUILD_SHARED_LIBS=OFFBUILD_SHARED_LIBSis ignored. ./ros2_dir/install/setup.bashcolcon build --cmake-args -DBUILD_SHARED_LIBS=OFFBUILD_SHARED_LIBSis ignoredSecond attempt:
ros2from source, withcolcon build --symlink-installcolcon build --packages-select rcutils rclcpp rcl_interfaces rcl --cmake-args -DBUILD_SHARED_LIBS=OFF. ./ros2_dir/install/setup.bashcolcon buildI could be totally misunderstanding the issue and I apologize - it's been a long time since I've worked with CMake files and adding another layer of abstraction above that (
colconand ROS2) has made it so I really can't figure this out myself.Do you have any documentation on how to setup ROS2 (and
colcon) to build statically from a fresh source code download ofros2? I've seen some of your previous comments (ros2/ros2#468) and that it does look possible for objective-C (https://github.com/esteve/ros2_objc), but I can't find exactly what needs to be done to make sure everything is working as expected.EDIT:
I should also add that I took a look into the
installfolder of the static build ofrclcpp, and I found the static library does exist:However, the binary built from the example still wants to look for the
.sofile? (Even when built without the symlink option)dirk-thomas commentedon Dec 27, 2018
Yes. The rational is simple: a package like
rclcppprovides a libraryrclcpp- by default a shared library but using the CMake option it can also be built into a static library. An example package builds an executable which is linked to other libraries likerclcpp. If you want the example to not depend on any shared libraries you need to build all packages providing libraries used by that executable using that CMake option.Without sharing the actual error message I can't provide any help.
There will be more recursive dependencies than the ones I explicitly mentioned. Rather than manually enumerating those that information is available from the package manifest files and can be extracted automatically.
Not every package will support to be built into static libraries. E.g. you can only have one typesupport package (otherwise it needs to build shared libraries to choose one of them at runtime). So you might want to limit the build to packages you actually want to use and only have a single RMW implementation installed (e.g. only FastRTPS but not Debian packages for Connext and OpenSplice). Then you should be able to run this build:
You can list multiple package names behind
--packages-up-to.In principle this approach should work (and it has in the past) but a quick test shows that it currently fails for several packages. I have created ros2/ros2#635 to track the problem with some ROS packages.
Since this is not a problem in
colconitself I will go ahead an close this issue in favor of the newly created one.eeyang92 commentedon Dec 27, 2018
Ah,
--packages-up-tois really handy!Sorry, I should have included the error message I received before:
Which ties into what you said about not all modules being able to be built statically.
Running with
colcon build --packages-up-to examples_rclcpp_minimal_publisher --packages-ignore rosidl_typesupport_introspection_c rosidl_typesupport_introspection_cpp rosidl_generator_py rmw_fastrtps_dynamic_cpp --cmake-args -DBUILD_SHARED_LIBS=OFF --no-warn-unused-cli, I get:-fPICcauses it to not build at all:But it seems like you've also confirmed it isn't working, so for now, I'll leave it as is, since I'm not at a point where I absolutely need a standalone executable (although it is planned down the road).
Thanks for your help! I will keep an eye out on ros2/ros2#635