ruijiege

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

main.cpp

#include <iostream>

int main()
{
    int num_a, num_b;
    num_a = 10;
    num_b = 20;
    std::cout << "num_a = " << num_a << std::endl;
    std::cout << "num_b = " << num_b << std::endl;
    return 0;
}
View Code

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(cmake_debug)

add_executable(cmake_debug main.cpp)
View Code

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        // 1. cmake 配置
        {
            "type": "cppbuild",
            "label": "CMake: 配置",
            "command": "cmake",
            "args": [
                "-DCMAKE_BUILD_TYPE=Debug",
                "-S .",
                "-B Build"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceFolder}"
            }
        },
        // 2. cmake 构建
        {
            "type": "cppbuild",
            "label": "CMake: 构建",
            "command": "cmake",
            "args": [
                "--build",
                "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/cmake_debug",
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "dependsOn": [
                "CMake: 构建"
            ]
        }
        
    ]
}
View Code

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "C++ CMake Debug",
            "program": "${workspaceFolder}/Build/cmake_debug",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "CMake: 构建"
        }
    ]
}
View Code

 

posted on 2023-06-14 14:41  哦哟这个怎么搞  阅读(16)  评论(0编辑  收藏  举报