ros2 CMakeLists.txt与packages.xml写法

使用ament_cmake_auto构建ROS2节点
本文档展示了如何使用ament_cmake_auto编写cmakelists.txt,并声明依赖的ROS2包。通过示例代码,说明了如何链接库和添加源文件,以及配置ament包。同时,提供的packages.xml文件列出了所有依赖项,包括nav_msgs、chassis_control等。

:尽量使用ament_cmake_auto来编写cmakelists.txt文件,依赖的程序包在packages.xml文件中用<depend>nav_msgs</depend>的形式声明,一些找不到的动态链接库可以用target_link_libraries的方式书写

cmake_minimum_required(VERSION 3.5)
project(nolinear_mpc_control)
if(NOT CMAKE_CXX_STANDARD)
    set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()

add_definitions(-fPIC)

#find_package(catkin REQUIRED COMPONENTS roscpp std_msgs)
find_package(ament_cmake_auto REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(ackermann_msgs REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(chassis_control REQUIRED)

#find_package(rosidl_default_generators REQUIRED)
ament_auto_find_build_dependencies()

ament_auto_add_executable(nolinearMPCNode 
  src/MPCNode.cpp
  src/NolinearMPC.cpp
)
target_link_libraries(nolinearMPCN
CMake Error at xarm_ros/xarm_api/CMakeLists.txt:96 (add_executable): Cannot find source file: my_cpp/v_line_test.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at xarm_ros/xarm_api/CMakeLists.txt:85 (add_executable): Cannot find source file: my_cpp/admittance_a.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at xarm_ros/xarm_api/CMakeLists.txt:77 (add_executable): Cannot find source file: aaa/test_mode5.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at xarm_ros/xarm_api/CMakeLists.txt:81 (add_executable): Cannot find source file: test/my_testa.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at xarm_ros/xarm_api/CMakeLists.txt:88 (add_executable): Cannot find source file: my_cpp/admittance_n.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at xarm_ros/xarm_api/CMakeLists.txt:92 (add_executable): Cannot find source file: my_cpp/v_line_M.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at xarm_ros/xarm_api/CMakeLists.txt:96 (add_executable): No SOURCES given to target: v_line_test CMake Error at xarm_ros/xarm_api/CMakeLists.txt:85 (add_executable): No SOURCES given to target: admittance_a CMake Error at xarm_ros/xarm_api/CMakeLists.txt:77 (add_executable): No SOURCES given to target: test_mode5 CMake Error at xarm_ros/xarm_api/CMakeLists.txt:81 (add_executable): No SOURCES given to target: my_testa CMake Error at xarm_ros/xarm_api/CMakeLists.txt:88 (add_executable): No SOURCES given to target: admittance_n CMake Error at xarm_ros/xarm_api/CMakeLists.txt:92 (add_executable): No SOURCES given to target: v_line_M CMake Generate step failed. Build files cannot be regenerated correctly. Invoking "cmake" failed
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值