linux下Cmake和vscode的配置
C 环境安装: sudo apt update sudo apt install build-essential gdb sudo apt install cmake gcc --version g --version gdb --version cmake --version C/C Themes CMake 写CMakeLists.txt能提示{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息请访问: https://go.microsoft.com/fwlink/?linkid830387 version: 0.2.0, configurations: [ { name: C Launch, type: cppdbg, request: launch, # 要调试的文件路径 program: /home/lgc/demo/07_calib/OpenCalib-master/lidar2camera/manual_calib/bin/run_lidar2camera, // 编译后的可执行文件 // 要调试的参数 args: [data/0.png,data/0.pcd,data/center_camera-intrinsic.json,data/top_center_lidar-to-center_camera-extrinsic.json], // stopAtEntry: false, //先切换到什么路径与参数有关 cwd: ${workspaceFolder}/lidar2camera/manual_calib, environment: [], externalConsole: false, MIMode: gdb, miDebuggerPath: /usr/bin/gdb, setupCommands: [ { description: Enable pretty-printing for gdb, text: -enable-pretty-printing, ignoreFailures: true } ], //preLaunchTask: build //如果不用编译,可以不要 } ] }task.josn { version: 2.0.0, options: { cwd: ${workspaceFolder}/build //需要进入到我们执行tasks任务的文件夹中 }, tasks: [ //tasks包含三个小任务 { type: shell, label: cmake, //第一个任务的名字叫cmake command: cmake, //它要执行的命令是cmake args: [ -DCMAKE_BUILD_TYPEDebug, .. //参数是.. ] }, { type: shell, label: make, //第二个任务的名字叫make group: { kind: build, isDefault: true }, command: make, //它要执行的命令是make args: [], options: { cwd: ${workspaceFolder}/build, }, }, { label: build, //第三个任务的名字叫build dependsOrder: sequence, //顺序执行依赖项 dependsOn:[ //依赖的两个项为cmake和make cmake, //即第一个任务的label make //即第二个任务的label ] } ] }setting.json:要调试的cmake文件 { cmake.sourceDirectory: /home/lgc/demo/07_calib/OpenCalib-master/lidar2camera/manual_calib // 整体界面缩放相当于 Ctrl/- 的效果 window.zoomLevel: 1.5, // 可选单独调整编辑器字体 editor.fontSize: 20, // 可选调整终端字体 terminal.integrated.fontSize: 15 }终端--运行生成任务--生成tasks.json ,主要是减少cmake指令 { version: 2.0.0, tasks: [ // 1. cmake 配置 { type: shell, label: CMake: 配置, command: cmake, args: [ -S, ${workspaceFolder}, -B, ${workspaceFolder}/build, -DCMAKE_BUILD_TYPEDebug ], problemMatcher: $msCompile, group: { kind: build, isDefault: true }, options: { cwd: ${workspaceFolder} } }, // 2. cmake 构建 { type: shell, label: CMake: 构建, command: cmake, args: [ --build, ${workspaceFolder}/build ], problemMatcher: $msCompile, group: { kind: build, isDefault: true }, options: { cwd: ${workspaceFolder} }, dependsOn: [ CMake: 配置 ] }, // 3. 删除Build目录 { type: shell, label: 删除Build目录, command: rm, args: [ -rf, build ], problemMatcher: $msCompile, group: { kind: build, isDefault: true }, options: { cwd: ${workspaceFolder} } }, // 4. 运行可执行文件 { type: shell, label: 运行可执行文件, command: ./Build/main, problemMatcher: $msCompile, group: { kind: build, isDefault: true }, options: { cwd: ${workspaceFolder} }, dependsOn: [ CMake: 构建 ] } ] }launch.json #可以用which gdb 查看dgb的路径 gdb --version 查看gdb的版本 点CMake Configure即可调试CMakeLists.txt文件还要安装CMake Tools工具 { // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息请访问: https://go.microsoft.com/fwlink/?linkid830387 version: 0.2.0, configurations: [ { name: C CMake Debug, type: cppdbg, request: launch, program: ${workspaceFolder}/Build/${fileBasenameNoExtension}, // 编译后的程序需要结合CMakeLists.txt中的add_executable()函数 args: [], stopAtEntry: false, cwd: ${workspaceFolder}, environment: [], externalConsole: false, MIMode: gdb, miDebuggerPath: /usr/bin/gdb, setupCommands: [ { description: Enable pretty-printing for gdb, text: -enable-pretty-printing, ignoreFailures: true } ], preLaunchTask: CMake: 构建 },{ name: CMake Debug, type: cmake, request: launch, scriptPath: /home/standard/yolo/ncnn/CMakeLists.txt, cmakeDebugType: script, }, { name: CMake Configure, type: cmake, request: launch, cmakeDebugType: configure } ] }c_cpp_properties.json vscode调试时查找头文件的路径 { configurations: [ { name: Linux, includePath: [ ${workspaceFolder}/**, /usr/include/opencv4 ], defines: [], compilerPath: /usr/bin/gcc, cStandard: gnu17, cppStandard: gnu14, intelliSenseMode: linux-gcc-x64 } ], version: 4 }如何断点调试CMakeLists.txt文件参考文档:https://github.com/microsoft/vscode-cmake-tools/blob/51b7ced409a4e0e26c036d4284d5077cbad66318/docs/debug.md1、首先安装cmake tools,cmake的版本版本必须大于3.272、launch.json中填写{ version: 0.2.0, configurations: [ { type: cmake, request: launch, name: Debug CMake Configure (yolov8), cmakeDebugType: configure, clean: true, configureAll: false } ] }3、设置settings.json{ cmake.sourceDirectory: ${workspaceFolder}/examples/yolov8/cpp, cmake.buildDirectory: ${workspaceFolder}/build/cmake-debug/yolov8-rk3588, cmake.generator: Unix Makefiles, cmake.configureArgs: [ -DTARGET_SOCrk3588, -DCMAKE_SYSTEM_NAMELinux, -DCMAKE_SYSTEM_PROCESSORaarch64, -DCMAKE_BUILD_TYPERelease, -DENABLE_ASANOFF, -DDISABLE_RGAOFF, -DDISABLE_LIBJPEGOFF, -DCMAKE_INSTALL_PREFIX${workspaceFolder}/install/rk3588_linux_aarch64/rknn_yolov8_demo ] } 这些项的原理 cmake.sourceDirectory 指定真正包含 CMakeLists.txt 的源码目录。因为 rknn_model_zoo 根目录不是直接构建 yolov8而是它下面的 examples/yolov8/cpp。 cmake.buildDirectory 指定构建输出目录。这样不会把中间文件散落到源码目录。 cmake.generator 指定生成器这里是 Unix Makefiles所以后面通常走 make。 cmake.configureArgs 这就是你手敲命令时 -Dxxxyyy 的图形化版本。CMake Tools 点“配置”时会自动把这些参数带上。 一句话理解这份 settings.json 是在告诉 VSCode/Cursor“如果你帮我跑 cmake请按这套参数跑”。4、点CMake Configure即可断点调试CmakeLists.txt文件
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2442956.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!