CMakeLists.txt confusion..

asked 2018-12-01 12:53:22 -0500

Hypomania gravatar image

updated 2022-01-22 16:16:22 -0500

Evgeny gravatar image

Hi,

I am using Ubuntu 16.04 LTS with ROS Kinetic distro.

I have a custom package called gps_msgs in my catkin_ws directory. I have other two packages that utilize the message by including it into source.

Now, one of the packages doesn't build without having "gps_msgs" inside the find_package() macro in CMakeLists.txt whereas the other one does.

The packages are nearly identical apart from the fact that one of them utilizes a 3rd party library. Here's the CMakeLists (package.xml files are almost identical, none of them include gps_msgs, I would like to know why that works too..):

Package #1:

cmake_minimum_required(VERSION 2.8.3)
project(can_control_node)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

add_executable(can_control_node src/control_node.cpp)
target_link_libraries(can_control_node ${catkin_LIBRARIES})

Package #2:

cmake_minimum_required(VERSION 2.8.3)
project(gps)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)

catkin_package(
  #CATKIN_DEPENDS std_msgs roscpp
  #INCLUDE_DIRS include
)

set(SOURCES
  src/an_packet_protocol.c
  src/spatial_packets.c
  src/rs232.c
)

include_directories(include/${PROJECT_NAME} ${catkin_INCLUDE_DIRS})


add_executable(gps_node 
  src/gps_node.cpp
  ${SOURCES}
)

target_link_libraries(gps_node ${catkin_LIBRARIES})

Again, both packages have #include <gps_msgs/Navigation.h> in their source files. The gps_msgs/Navigation isn't mentioned AT ALL in either of the package.xml files. Package #1 builds, package #2 complains that gps_msgs/Navigation doesn't exist. All 3 packages are in separate directories in my catkin_ws, what's going on?

edit retag flag offensive close merge delete

Comments

1

Any ideas? I am getting quite desperate here..

please check the catkin documentation on how to properly add library, pkg and msg/srv/action dependencies. You're CMakeLists.txt are missing a few bits.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-03 02:38:56 -0500 )edit

@gvdhoorn, could you please pinpoint which parts exactly? I am not trying to export the packages, just build and link the targets.. Two almost identical packages, one needs gps_msgs package the other one doesn't..

Hypomania gravatar image Hypomania  ( 2018-12-03 02:47:34 -0500 )edit
1

The keyword here is dependencies. You're not telling CMake/Catkin how your packages are related/depend on each other. You write it yourself:

The gps_msgs/Navigation isn't mentioned AT ALL in either of the package.xml files

Similarly, your CMakeLists.txt doesn't refer to gps_msgs either ..

gvdhoorn gravatar image gvdhoorn  ( 2018-12-03 02:49:08 -0500 )edit

.. How do you expect CMake to build your packages in the correct order and make sure that pkg nr 2 can access those include files if you don't tell it that it needs to make sure things are in the proper place at the proper times?

gvdhoorn gravatar image gvdhoorn  ( 2018-12-03 02:50:19 -0500 )edit

@gvdhoorn, I understand that perfectly, what I don't understand is how package #1 resolves its gps_msgs dependency without ANY mentioning of it whatsoever`

Hypomania gravatar image Hypomania  ( 2018-12-03 02:53:03 -0500 )edit

@gvdhoorn, to add more, I am #including std_msgs/String but it's not mentioned in its CMakeLists.txt or package.xml files.. weird!

Hypomania gravatar image Hypomania  ( 2018-12-03 02:55:39 -0500 )edit
1

I am #including std_msgs/String but it's not mentioned in its CMakeLists.txt or package.xml files.. weird!

nothing too weird about that: std_msgs is a package that you're most likely not building yourself, but installed using apt. So it's always available, and so are the files.

gvdhoorn gravatar image gvdhoorn  ( 2018-12-03 02:57:24 -0500 )edit

@gvdhoorn, okay, that makes sense, what about the custom msg in my catkin_ws? How does it find that?

Hypomania gravatar image Hypomania  ( 2018-12-03 02:58:40 -0500 )edit