VSCode使用CMake来debug
程序员文章站
2022-05-15 20:51:57
...
使用VSCode远程连接服务器
配置文件使用CMake来debug
-
建立build.sh脚本文件
-
建立build文件夹
build.sh脚本文件内容如下
cd build #切换到build文件夹
rm -rf * #删除build文件夹下内容
cmake -DCMAKE_BUILD_TYPE=Debug .. #启动cmake来debug,若不debug可注释
cmake .. #生成makefile各类文件
make -j8 #执行makefile文件
- c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/local/include/eigen3",
"/usr/include/c++/7",
"/usr/include/x86_64-linux-gnu/c++/7",
"/usr/include/c++/7/backward",
"/usr/lib/gcc/x86_64-linux-gnu/7/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed",
"/usr/include/x86_64-linux-gnu"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
- settings.json
{
"files.associations": {
"*.ipp": "cpp",
"iosfwd": "cpp",
"fstream": "cpp"
}
}
- tasks.json
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "make",
"command": "sh build.sh"
}
]
}
- launch.json这个比较复杂
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/src/exe/colmap",
"args": [
"feature_extractor",
"--database_path",
"$DATASET_PATH/database.db",
"--image_path",
"/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Train/images/",
],
// "args": [
// "exhaustive_matcher",
// "--database_path",
// "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Train/database.db"
// ],
// "args": [
// "hierarchical_mapper",
// "--database_path",
// "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Train/database.db",
// "--image_path",
// "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Train/images",
// "--output_path",
// "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Train/sparse"
// ],
"stopAtEntry": false,
"cwd": "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Train",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make"
}
]
}
-"preLaunchTask": "make"
调试会话前要运行的任务
-"program": "${workspaceFolder}/build/src/exe/colmap"
程序可执行文件的完整路径
-"cwd": "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Playground"
目标的工作目录(存放图片的路径)
-"args": [ "feature_extractor", "--database_path", "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Playground/database.db", "--image_path", "/data6/wcm/document/TanksAndTemples/tankandtemples/intermediate/Playground/images/", ],
传递给程序的命令行参数。
colmap的命令为
$ DATASET_PATH=/path/to/dataset
$ colmap feature_extractor \
--database_path $DATASET_PATH/database.db \
--image_path $DATASET_PATH/images
此处的 ,
相当于命令行的空格。$DATASET_PATH
写绝对路径不会报错。
可以写多个args
,把不需要执行的注释掉。
执行完 feature_extractor
后,cwd目录下生成了database.db文件