当前位置: 首页 > article >正文

c++ vscode cmake debug for mac

1. 下载vscode

2. 安装c++插件

参考:C++ programming with Visual Studio Code

3. 安装llvm,可以使用brew安装

4. 配置llvm到系统环境变量中

5. 编写c++代码

6. 编写CMakeLists.txt文件(前提安装cmake)

cmake_minimum_required(VERSION 3.5)

project(vscode_cmake_debug)

# 设置可执行文件的输出路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

# 重点
set(CMAKE_BUILD_TYPE "Debug")

add_executable(main src/main.cpp)

7. 生成vscode中c++的智能提示文件c_cpp_properties.json

可参考:https://code.visualstudio.com/docs/cpp/config-clang-mac

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/opt/homebrew/opt/llvm/bin/clang",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}

8. 生成vscode debug文件launch.json

具体可参考:Configure VS Code for Clang/LLVM on macOS

{
    // 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": "Debug",
            "type": "lldb",
            "request": "launch",            
            "program": "${workspaceFolder}/cmake_debug/bin/main",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            //"preLaunchTask": "C/C++: g++ build active file",
            //"miDebuggerPath": "lldb的路径"
        }
    ]
}

其中部分字段配置可参考:

https://code.visualstudio.com/docs/editor/variables-reference

和Configure launch.json for C/C++ debugging in Visual Studio Code

因为已经采用cmake编译,所以launch中的preLaunchTask可以不用关联task了

参考文件:

c++程序的 cmake编译+vscode来debug 方法和步骤(ubuntu)_cmake 如何debug-CSDN博客


http://www.kler.cn/a/104981.html

相关文章:

  • 汽车4S店如何在数字化管理下,提高市场竞争力
  • 本地新建项目如何推到码云上去
  • Spring Security系例—漏洞防御
  • 解决javascript报错:SyntaxError: Invalid Unicode escape sequence
  • C++(Qt)软件调试---线程死锁调试(15)
  • C++内存管理:其七、标准库中的allocator
  • linux中断下文工作队列之共享工作队列(中断四)
  • 【RTT驱动框架分析】- 队列DataQueue源码分析
  • RHCE---Shell基础 2
  • PG14启动报错“max_stack_depth“ must not exceed 7680kB
  • 1.AUTOSAR的架构及方法论
  • 六零导航页SQL注入漏洞复现(CVE-2023-45951)
  • RabbitMQ基础篇 笔记
  • Spring Boot集成Swagger接口分类与各元素排序问题
  • 基于WebRTC构建的程序因虚拟内存不足导致闪退问题的排查以及解决办法的探究
  • 【ELK】日志系统部署
  • PHP 数据库交互优化,根据传参查询
  • 深入理解强化学习——强化学习的历史:近代强化学习的发展
  • 0037【Edabit ★☆☆☆☆☆】【修改Bug 2】Buggy Code (Part 2)
  • k8s 1.28版本:使用StorageClass动态创建PV,SelfLink 问题修复