Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rosbag2_storage_mcap] Bugs in generated CMake targets? #1492

Closed
EricCousineau-TRI opened this issue Nov 13, 2023 · 6 comments
Closed

[rosbag2_storage_mcap] Bugs in generated CMake targets? #1492

EricCousineau-TRI opened this issue Nov 13, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@EricCousineau-TRI
Copy link

Description

Unable to depend on rosbag2_storage_mcap via CMake / ament.

Expected Behavior

It should work.

Actual Behavior

We get the following errors:

CMake Error at CMakeLists.txt:19 (add_library):
  Target "empty_using_rosbag2_storage_mcap" links to target
  "mcap_vendor::mcap" but the target was not found.  Perhaps a find_package()
  call is missing for an IMPORTED target, or an ALIAS target is missing?


CMake Error in CMakeLists.txt:
  Imported target "rosbag2_storage_mcap::rosbag2_storage_mcap" includes
  non-existent path

    "/opt/ros/humble/include/rosbag2_storage_mcap"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

To Reproduce

Install ROS 2 Humble on Ubuntu 22.04.
Then run the following:

sudo apt install ros-humble-rosbag2-storage-mcap

mkdir /tmp/example && cd /tmp/example
cat <<'EOF'
cmake_minimum_required(VERSION 3.5)
project(empty_using_rosbag2_storage_mcap C CXX)

find_package(ament_cmake REQUIRED)
find_package(rosbag2_storage_mcap REQUIRED)

file(WRITE empty.cc "")
add_library(${PROJECT_NAME} SHARED empty.cc)

ament_target_dependencies(${PROJECT_NAME} rosbag2_storage_mcap)
target_link_libraries(${PROJECT_NAME} rosbag2_storage_mcap)
EOF

mkdir build && cd build
source /opt/ros/humble/setup.bash
cmake ..

System (please complete the following information)

  • OS: Ubuntu Jammy 22.04
  • ROS 2 Distro: Humble
  • Install Method: Apt
  • Version: 0.15.8-1jammy.20230919.224231

Additional context

Root cause of RobotLocomotion/drake-ros#315
Workaround in RobotLocomotion/drake-ros#316

@MichaelOrlov
Copy link
Contributor

@EricCousineau-TRI I've briefly checked CMake.txt file for the rosbag2_storage_macp for reference to the mcap_vendor package
and we do have both find_package(mcap_vendor REQUIRED) and ament_target_dependencies(${PROJECT_NAME mcap_vendor)

find_package(mcap_vendor REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rcutils REQUIRED)
find_package(rosbag2_storage REQUIRED)
add_library(${PROJECT_NAME} SHARED
src/mcap_storage.cpp
src/message_definition_cache.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
target_compile_features(${PROJECT_NAME} PUBLIC c_std_99 cxx_std_17)
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROSBAG2_STORAGE_MCAP_BUILDING_DLL")
ament_target_dependencies(${PROJECT_NAME}
mcap_vendor
pluginlib
rcutils
rosbag2_storage)

I don't remember that we promised that any of ROS2 core packages would compile with the plain cmake .. command.
The proper way to compile code in ROS2 is using colocn build command.
Have you tried to reproduce the problem if you would create a proper ROS2 package that is dependent on rosbag2_storage_mcap and build it with colcon build ?

@clalancette
Copy link
Contributor

I don't remember that we promised that any of ROS2 core packages would compile with the plain cmake .. command.

Actually, this has to work; that is how the buildfarm produces binary packages (it does not use colcon).

So it is curious that doing it "by hand" this way doesn't work. It probably needs a bit more debugging to see what is going on here.

@EricCousineau-TRI
Copy link
Author

@MichaelOrlov The CMakeLists.txt you pointed out I believe is relevant for source builds, but not for consuming binaries installs of rosbag2_storage_mcap (using the installed artifacts).

I am able to reproduce this in a minimal colcon setup, which effectively shows the same behavior:

rm -rf /tmp/colcon-example && mkdir /tmp/colcon-example && cd /tmp/colcon-example
mkdir -p src/example

cat > src/example/CMakeLists.txt <<'EOF'
cmake_minimum_required(VERSION 3.14)
project(example)

find_package(ament_cmake REQUIRED)
find_package(rosbag2_storage_mcap REQUIRED)

file(WRITE empty.cc "")
add_library(${PROJECT_NAME} SHARED empty.cc)

ament_target_dependencies(${PROJECT_NAME} rosbag2_storage_mcap)
target_link_libraries(${PROJECT_NAME} rosbag2_storage_mcap)

ament_package()
EOF

cat > src/example/package.xml <<'EOF'
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>example</name>
  <version>0.0.1</version>
  <description>thing</description>
  <maintainer email="[email protected]">Meh</maintainer>
  <license>Apache-2.0</license>
  <buildtool_depend>ament_cmake</buildtool_depend>
  <depend>rosbag2_storage_map</depend>
  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
EOF

source /opt/ros/humble/setup.bash
colcon build

@MichaelOrlov
Copy link
Contributor

@EricCousineau-TRI Thanks for trying to reproduce with colcon build.
Now it seems I know why it fails to build.
We have missing dependencies in the ament_export_dependencies(rosbag2_storage rcutils)

ament_export_libraries(${PROJECT_NAME})
ament_export_targets(export_${PROJECT_NAME})
ament_export_dependencies(rosbag2_storage rcutils)
ament_package()

Perhaps the fix would be to add missing mcap_vendor and pluginlib to the ament_export_dependencies.

The reason why it works in CI and other workflow is that we are using rosbag2_storage_mcap as a runtime loading library and never compiled directly against it.

@ahcorde
Copy link
Contributor

ahcorde commented Nov 14, 2023

I openned a PR #1496

@ahcorde
Copy link
Contributor

ahcorde commented Nov 20, 2023

The PR was merged and backported to iron and humble. Feel free to reopen the issue if the problem persists

@ahcorde ahcorde closed this as completed Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants