在ubuntu配置pcl點云庫以及opencv庫的時候,需要在CMakeLists.txt中加入相應的代碼。配置完成后,無法調試,與在windows上體驗vs studio差別有點大。
找了好多調試debug配置方法,最終能用的有幾種,但是有一種特別好用,具體不清楚原理,但是不用配置含路徑和庫文件路徑和文件,簡直是讓人驚嘆。
有人配置c_cpp_properties.json,我沒有配置,網上說是這個相當于
配置 IntelliSense 功能,我只配置了 tasks.json 和launch.json文件。
1. task.json
{ "version": "2.0.0","options": {"cwd": "${workspaceFolder}/build"},"tasks": [{"type": "shell","label": "cmake","command": "cmake","args": [".."]},{"label": "make","group": {"kind": "build","isDefault": true},"command": "make","args": []},{"label": "Build","dependsOrder": "sequence", // 按列出的順序執行任務依賴項"dependsOn":["cmake","make"]}]
}
2.launch.json,其中program要換成自己的可執行文件
{// 使用 IntelliSense 了解相關屬性。// 懸停以查看現有屬性的描述。// 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "g++ - 生成和調試活動文件","type": "cppdbg","request": "launch","program": "${workspaceFolder}/build/devel/lib/litamin2/litamin2_align","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "為 gdb 啟用整齊打印","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "Build","miDebuggerPath": "/usr/bin/gdb"}]
}
3.要在CMakeLists.txt中加入:
set(CMAKE_BUILD_TYPE "Debug")
并去掉優化選項(比如O3優化等),否則會亂跳。
4.調試
點擊三角形+爬蟲的 符號,進入調試,選擇
選擇這一個就可以開始編譯+調試了。
在這里有一個技巧:如果事先在終端中cmake .. 和make之后,這里調試啟動就特別快。
參考:
https://zhuanlan.zhihu.com/p/688006076