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

Revision history [back]

click to hide/show revision 1
initial version

Package foo is exporting the library target foo in the foo:: namespace.

# Export targets.
set(export_targets ${export_targets};${PROJECT_NAME})
export(
  EXPORT export_${PROJECT_NAME}
  FILE "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
  NAMESPACE ${PROJECT_NAME}::
)

But bar is trying to link against foo with no namespace.

## Declare a cpp executable
add_executable(Bar src/bar.cpp)
ament_target_dependencies(Bar rclcpp)
target_link_libraries(Bar foo)

Change it to foo::foo to match what foo is exporting

target_link_libraries(Bar foo::foo)

In case you see this again, when debugging CMake packages not finding another package's headers I find it's helpful to use CMAKE_VERBOSE_MAKEFILE.

colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_VERBOSE_MAKEFILE=TRUE

That showed foo's include directory wasn't being passed to the compiler, which suggested I should look at pure CMake issues first.

[ 50%] Building CXX object CMakeFiles/Bar.dir/src/bar.cpp.o
/usr/bin/c++   -I/tmp/ros2_cmake_test/bar/include -I/opt/ros/eloquent/include  -Wall -Wextra -Wpedantic -std=gnu++14 -o CMakeFiles/Bar.dir/src/bar.cpp.o -c /tmp/ros2_cmake_test/bar/src/bar.cpp

Package foo is exporting the library target foo in the foo:: namespace.

# Export targets.
set(export_targets ${export_targets};${PROJECT_NAME})
export(
  EXPORT export_${PROJECT_NAME}
  FILE "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
  NAMESPACE ${PROJECT_NAME}::
)

But bar is trying to link against exported library target foo with no namespace.

## Declare a cpp executable
add_executable(Bar src/bar.cpp)
ament_target_dependencies(Bar rclcpp)
target_link_libraries(Bar foo)

Change it to foo::foo to match what foo is exporting

target_link_libraries(Bar foo::foo)

In case you see this again, when debugging CMake packages not finding another package's headers I find it's helpful to use CMAKE_VERBOSE_MAKEFILE.

colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_VERBOSE_MAKEFILE=TRUE

That showed foo's include directory wasn't being passed to the compiler, which suggested I should look at pure CMake issues first.

[ 50%] Building CXX object CMakeFiles/Bar.dir/src/bar.cpp.o
/usr/bin/c++   -I/tmp/ros2_cmake_test/bar/include -I/opt/ros/eloquent/include  -Wall -Wextra -Wpedantic -std=gnu++14 -o CMakeFiles/Bar.dir/src/bar.cpp.o -c /tmp/ros2_cmake_test/bar/src/bar.cpp

Package foo is exporting the library target foo in the foo:: namespace.

# Export targets.
set(export_targets ${export_targets};${PROJECT_NAME})
export(
  EXPORT export_${PROJECT_NAME}
  FILE "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
  NAMESPACE ${PROJECT_NAME}::
)

But bar is trying to link against exported library target foo with no namespace.

## Declare a cpp executable
add_executable(Bar src/bar.cpp)
ament_target_dependencies(Bar rclcpp)
target_link_libraries(Bar foo)

Change it to foo::foo to match what package foo is exporting

target_link_libraries(Bar foo::foo)

In case you see this again, when debugging CMake packages not finding another package's headers I find it's helpful to use CMAKE_VERBOSE_MAKEFILE.

colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_VERBOSE_MAKEFILE=TRUE

That showed foo's include directory wasn't being passed to the compiler, which suggested I should look at pure CMake issues first.

[ 50%] Building CXX object CMakeFiles/Bar.dir/src/bar.cpp.o
/usr/bin/c++   -I/tmp/ros2_cmake_test/bar/include -I/opt/ros/eloquent/include  -Wall -Wextra -Wpedantic -std=gnu++14 -o CMakeFiles/Bar.dir/src/bar.cpp.o -c /tmp/ros2_cmake_test/bar/src/bar.cpp

Package foo is exporting the library target foo in the foo:: namespace.

# Export targets.
set(export_targets ${export_targets};${PROJECT_NAME})
export(
  EXPORT export_${PROJECT_NAME}
  FILE "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
  NAMESPACE ${PROJECT_NAME}::
)

But bar package bar is trying to link against exported library target foo with no namespace.

## Declare a cpp executable
add_executable(Bar src/bar.cpp)
ament_target_dependencies(Bar rclcpp)
target_link_libraries(Bar foo)

Change it to foo::foo to match what package foo is exporting

target_link_libraries(Bar foo::foo)

In case you see this again, when debugging CMake packages not finding another package's headers I find it's helpful to use CMAKE_VERBOSE_MAKEFILE.

colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_VERBOSE_MAKEFILE=TRUE

That showed foo's include directory wasn't being passed to the compiler, which suggested I should look at pure CMake issues first.

[ 50%] Building CXX object CMakeFiles/Bar.dir/src/bar.cpp.o
/usr/bin/c++   -I/tmp/ros2_cmake_test/bar/include -I/opt/ros/eloquent/include  -Wall -Wextra -Wpedantic -std=gnu++14 -o CMakeFiles/Bar.dir/src/bar.cpp.o -c /tmp/ros2_cmake_test/bar/src/bar.cpp

Package foo is exporting the library target foo in the foo:: namespace.

# Export targets.
set(export_targets ${export_targets};${PROJECT_NAME})
export(
  EXPORT export_${PROJECT_NAME}
  FILE "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
  NAMESPACE ${PROJECT_NAME}::
)

But package bar is trying to link against exported library target foo with no namespace.

## Declare a cpp executable
add_executable(Bar src/bar.cpp)
ament_target_dependencies(Bar rclcpp)
target_link_libraries(Bar foo)

Change it to foo::foo to match what package foo is exporting

target_link_libraries(Bar foo::foo)

In case you see this again, when debugging CMake packages not finding another package's headers I find it's helpful to use CMAKE_VERBOSE_MAKEFILE.

colcon build --event-handlers console_direct+ --cmake-args -DCMAKE_VERBOSE_MAKEFILE=TRUE

That showed foo's include directory wasn't being passed to the compiler, which suggested I should look at pure CMake issues first.

[ 50%] Building CXX object CMakeFiles/Bar.dir/src/bar.cpp.o
/usr/bin/c++   -I/tmp/ros2_cmake_test/bar/include -I/opt/ros/eloquent/include  -Wall -Wextra -Wpedantic -std=gnu++14 -o CMakeFiles/Bar.dir/src/bar.cpp.o -c /tmp/ros2_cmake_test/bar/src/bar.cpp

After fixing the target name, foo's include directory is correctly passed to the compiler and the build succeeds.

[ 50%] Building CXX object CMakeFiles/Bar.dir/src/bar.cpp.o
/usr/bin/c++   -I/tmp/ros2_cmake_test/bar/include -I/opt/ros/eloquent/include -isystem /tmp/ros2_cmake_test/install/foo/include  -Wall -Wextra -Wpedantic -std=gnu++14 -o CMakeFiles/Bar.dir/src/bar.cpp.o -c /tmp/ros2_cmake_test/bar/src/bar.cpp