LINUX【ubuntu]vscode 配置C++ 编译环境CMAKE+外部库

1.launch.json

program:设置为编译之后的可执行文件。

{workspaceFolders}:当前打开的文件夹路径。

cwd:current work directory 程序当前目录。

2.tasks.json

tasks.json里的“label”须和launch.json的prelaunchTask一致,如两者都为“Build”

3.【UBUNTU20.04LTS】VSCODE CMAKE(含第三方库):

亲测有效的launch.json和tasks.json:

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", // 这一行的配置项非常重要
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "internalConsoleOptions": "neverOpen",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build", // 这一步也配置同样很重要,这一步工作负责源代码的编译
        }
    ]
}

tasks.json:

{   
    "version": "2.0.0",
    "options": {
        "cwd": "${workspaceFolder}/build" // "cwd"表示当前工作目录:current working directory;workspaceFolder表示工作空间文件夹
    },
    "tasks": [
        {
            "type": "shell",
            "label": "cmake", // 该任务的标签是:"cmake"
            "command": "cmake", // cmake任务生成makefile文件
            "args": [ // cmake命令后所跟的参数,".."表示在父目录
                ".."
            ]
        },
        {
            "label": "make", // 该任务的标签是:"label",根据makefile文件进行编译
            "group": {
                "kind": "build", // 当前任务所属的组是build组
                "isDefault": true 
            },
            "command": "make", // 在Windows下实际执行的命令是:mingw32-make
            "args": [ // mingw32-make命令后面所跟的参数
            ]
        },
        {
            "label": "Build", //这个名为"Build"的task是launch.json执行前所预先执行的任务
            "dependsOn":[ // 并且这个任务又依赖"cmake"和"make"这两个任务
                "cmake",
                "make"
            ]
        }
    ]
}

ctrl+shift+p:打开命令搜索框输入:CMake: Configure

选择GCC xxxxx选项

点击最下方build---》点击run(最下方的三角形)

注:

launch.json和tasks.json是自动生成的,须根据自己的工程进行修改

Vscode按文件夹打开。

时间:2023.07.05

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值