文章目录
- 1. 插件
- 2. 项目工程
- 3. vsode的配置
- setting.json
- c_cpp_properties.json
- 4. 启动调试
前置阅读
vscode调试第一篇
1. 插件
c/c++, cmake, cmake tools
2. 项目工程
对于我的项目需要用到很多的三方库,三方库的版本又会有很多,一般都是用cmake编译安装到指定的位置,最好的方式是三方库都放到一个非系统的文件夹下,后面要修改版本也和系统不冲突。这样的话就需要cmake在编译的时候find_package时指定库的搜索路径。每个开发人员的路径都不一样,所以这些路径都不会在cmakeLists里面有体现,都是在脚本里面指定。
代码量接近10万的项目。
例如下面的bash脚本是我的编译执行脚本:
# if [ -d "../build" ]; then
# rm -rf ../build
# fi
mkdir -p ../buildcd ../buildcmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DOpenCV_DIR="/media/xp/data/3rd_party/opencv481/lib/cmake/opencv4" \
# ..........其他的库
-DOCL_ROOT="/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/share/cmake/OpenCL" \
-DOpenCL_INCLUDE_DIR="/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/include" \
-DOpenCL_OpenCLUtilsCpp_LIBRARY="/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/lib/libOpenCLUtilsCpp.so" \
-DOpenCL_OpenCLUtils_LIBRARY="/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/lib/libOpenCLUtils.so" \
-DOpenCL_OpenCL_LIBRARY="/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/lib/libOpenCL.so" \
-DOpenCL_INCLUDE_DIR="/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/include" \
-DBUILD_SHARED_LIBS=ONmake -j32../build/demo/test
3. vsode的配置
setting.json
bash 命令中的cmake -DXXX=YYY的可以在里面添加cmake.configureSettings项,指定XXX:YYY
{"files.associations": {"cstring": "cpp","any": "cpp","array": "cpp","atomic": "cpp","bit": "cpp","*.tcc": "cpp","bitset": "cpp","cctype": "cpp","chrono": "cpp","cinttypes": "cpp","clocale": "cpp","cmath": "cpp","codecvt": "cpp","compare": "cpp","complex": "cpp","concepts": "cpp","condition_variable": "cpp","cstdarg": "cpp","cstddef": "cpp","cstdint": "cpp","cstdio": "cpp","cstdlib": "cpp","ctime": "cpp","cwchar": "cpp","cwctype": "cpp","deque": "cpp","forward_list": "cpp","list": "cpp","map": "cpp","set": "cpp","string": "cpp","unordered_map": "cpp","unordered_set": "cpp","vector": "cpp","exception": "cpp","algorithm": "cpp","functional": "cpp","iterator": "cpp","memory": "cpp","memory_resource": "cpp","numeric": "cpp","optional": "cpp","random": "cpp","ratio": "cpp","string_view": "cpp","system_error": "cpp","tuple": "cpp","type_traits": "cpp","utility": "cpp","fstream": "cpp","initializer_list": "cpp","iomanip": "cpp","iosfwd": "cpp","iostream": "cpp","istream": "cpp","limits": "cpp","mutex": "cpp","new": "cpp","numbers": "cpp","ostream": "cpp","semaphore": "cpp","span": "cpp","sstream": "cpp","stdexcept": "cpp","stop_token": "cpp","streambuf": "cpp","thread": "cpp","typeinfo": "cpp","valarray": "cpp","variant": "cpp","regex": "cpp"},"C_Cpp.errorSquiggles": "disabled","cmake.configureSettings": {"OpenCV_DIR": "/media/xp/data/3rd_party/opencv481/lib/cmake/opencv4",# 其他的三方库"OCL_ROOT": "/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/share/cmake/OpenCL","OpenCL_INCLUDE_DIR": "/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/include","OpenCL_OpenCLUtilsCpp_LIBRARY": "/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/lib/libOpenCLUtilsCpp.so","OpenCL_OpenCLUtils_LIBRARY": "/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/lib/libOpenCLUtils.so","OpenCL_OpenCL_LIBRARY": "/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/lib/libOpenCL.so","BUILD_SHARED_LIBS": "ON","clFFT_DIR": "/media/xp/data/3rd_party_lib/clFFT/2.14.0/gnu/share/clFFT"}
}
c_cpp_properties.json
vscode调试的时候跳转三方库头文件啥的,在这里面的includePath里面配置添加;
阅读代码会有很多宏变量,可以在defines中定义;
{"configurations": [{"name": "Linux","includePath": ["${workspaceFolder}/**","${workspaceFolder}/modules/surround_view_3d/include","${workspaceFolder}/modules/casting/include","/usr/local/include/glog","${workspaceFolder}/modules","/usr/local/include/opencv4","${workspaceFolder}/modules/widget/include","${workspaceFolder}/modules/surround_view_3d/include/common","/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/include","/media/xp/data/3rd_party_lib/opencl_sdk/2024.05.08/gnu/include/CL",],"defines": ["USE_OCL=0"],"compilerPath": "/usr/bin/gcc","cStandard": "c17","cppStandard": "gnu++17","intelliSenseMode": "linux-gcc-x64"}],"version": 4}
4. 启动调试