CMakeLists.txt confusion..
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?
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, 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..
The keyword here is dependencies. You're not telling CMake/Catkin how your packages are related/depend on each other. You write it yourself:
Similarly, your
CMakeLists.txt
doesn't refer togps_msgs
either .... 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, I understand that perfectly, what I don't understand is how package #1 resolves its
gps_msgs
dependency without ANY mentioning of it whatsoever`@gvdhoorn, to add more, I am #including std_msgs/String but it's not mentioned in its
CMakeLists.txt
orpackage.xml
files.. weird!nothing too weird about that:
std_msgs
is a package that you're most likely not building yourself, but installed usingapt
. So it's always available, and so are the files.@gvdhoorn, okay, that makes sense, what about the custom msg in my catkin_ws? How does it find that?