Please help with my CMakeLists.txt. Conflicting packages unable to build.
Hello! I am really confused on how to construct an appropriate CMakeLists.txt. I am trying to create a package and I was able to create all of the necessary nodes and they work seperately, but when I try to build it all together, I get a lot of errors.
The two packages causing problems are pclros and ocs2ros_interfaces (https://github.com/leggedrobotics/ocs2).
I am using ros noetic. Below is my CMakeLists.txt
cmake_minimum_required(VERSION 3.0.2)
project(sara_arm)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
actionlib
actionlib_msgs
pcl_msgs
pcl_ros
moveit_core
moveit_ros_planning
moveit_ros_planning_interface
sensor_msgs
tf2
tf2_ros
kinova_msgs
moveit_visual_tools
tf2_eigen
ocs2_ros_interfaces
)
add_service_files(
FILES
image_to_cloud_point.srv
)
generate_messages(
DEPENDENCIES
geometry_msgs # Or other packages containing msgs
sensor_msgs
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_executable(ocs2_sara src/ocs2_sara.cpp)
target_link_libraries(ocs2_sara ${catkin_LIBRARIES})
add_executable(pcp_sara src/pcp_sara.cpp)
target_link_libraries(pcp_sara ${catkin_LIBRARIES})
add_executable(sara_arm src/sara_arm.cpp)
target_link_libraries(sara_arm ${catkin_LIBRARIES})
The errors that pop up are referencing a lot of issues with pcl.
- If I comment out the pcpsara addexecutable and targetlinklibraries calls, it builds fine (but I cannot use that node, obviously)
- If I comment out the ocs2sara addexecutable and targetlinklibraries calls, it does not build and tells me I have tons of errors with pcl, similar to if I leave it uncommented
- If I comment out the ocs2sara addexecutable and targetlinklibraries calls AND the ocs2rosinterfaces from the findpakage() call, it builds fine, but I cannot use the ocs2sara node
I would appreciate any help, I am sure I am missing something (perhaps a catkinpackage() call) but since everything works independently, I am not sure what to do to make sure they work together. Is there something I can look into in the ocs2ros_interfaces that might be causing issues?
NOTE: ocs2rosinterfaces is cloned to my catkin_ws, while pcl (and all the other packages listed) are installed via sudo apt-get install.
Asked by ericdusel77 on 2022-07-09 17:51:02 UTC
Answers
I fixed it. This way works:
cmake_minimum_required(VERSION 3.0.2)
project(sara_arm)
set(CATKIN_PACKAGE_DEPENDENCIES
actionlib
actionlib_msgs
pcl_msgs
pcl_ros
moveit_core
moveit_ros_planning
moveit_ros_planning_interface
sensor_msgs
tf2
tf2_ros
kinova_msgs
moveit_visual_tools
tf2_eigen
ocs2_ros_interfaces
)
find_package(catkin REQUIRED COMPONENTS
${CATKIN_PACKAGE_DEPENDENCIES}
)
find_package(PCL REQUIRED)
add_service_files(
FILES
image_to_cloud_point.srv
)
generate_messages(
DEPENDENCIES
geometry_msgs # Or other packages containing msgs
sensor_msgs
)
###################################
## catkin specific configuration ##
###################################
catkin_package(
INCLUDE_DIRS
include
CATKIN_DEPENDS
${CATKIN_PACKAGE_DEPENDENCIES}
# DEPENDS
)
###########
## Build ##
###########
include_directories(
include
${catkin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)
# add_library(pcp_sara src/pcp_sara.cpp)
# add_library(sara_arm src/sara_arm.cpp)
add_executable(pcp_sara src/pcp_sara.cpp)
target_link_libraries(pcp_sara ${catkin_LIBRARIES} ${PCL_LIBRARIES})
add_executable(sara_arm src/sara_arm.cpp)
target_link_libraries(sara_arm ${catkin_LIBRARIES})
add_executable(ocs2_sara src/ocs2_sara.cpp)
target_link_libraries(ocs2_sara ${catkin_LIBRARIES})
Asked by ericdusel77 on 2022-07-10 11:07:00 UTC
Comments