C++ ros2 debug
Cmakelist 中加入如下:
# 针对 Debug 模式关闭优化
if(CMAKE_BUILD_TYPE STREQUAL "Debug")add_compile_options(-g -O0)# target_compile_options(mpc_node PRIVATE -g -O0)
else()# 发布模式可保持优化add_compile_options(-O2)
endif()
编译命令
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Debug
launch.json
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "ROS: Launch","type": "ros","request": "launch","target": "/home/acan/Acan_ros2_ws/exp/mpc_ros2/src/mpc_path_tracker/launch/mpc_path_tracker.launch.py"},]
}
或者使用
{"configurations": [{"name": "ROS2 Debug","type": "cppdbg","request": "launch","program": "${workspaceFolder}/install/mpc_path_tracker/lib/mpc_path_tracker/mpc_node","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [{"name": "ROS_DOMAIN_ID", "value": "0"}],"setupCommands": [{"text": "source install/setup.bash"}]}]
}