Ubuntu1604系统下的环境配置vscode和c++

Ubuntu1604系统下的环境配置vscode和c++

这一部分,是通用的C++编译、debug配置,主要涉及到两个文件。

launch.json配置

这个文件主要是配置debug,具体设置如下:

{
    // 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}/${fileBasenameNoExtension}.o",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}

task.json配置

可以点击Ctrl+Shift+P"调出命令面板,然后搜索Task,点击第一个模板,会提示你依据模板创建task.json,这里不管什么模板,随便选一个,然后直接复制粘贴以下设置代码:
在这里插入图片描述

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g", 
        "-std=c++11", 
        "${file}", 
        "-o", 
        "${fileBasenameNoExtension}.o",
    ],// 编译命令参数
    "problemMatcher":{
        "owner": "cpp",
        "fileLocation":[
            "relative",
            "${workspaceFolder}"
        ],
        "pattern":[
            {
                "regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$",
                "file": 1,
                "location": 2,
                "message": 3
            }
        ]
    },
    "group": {
        "kind": "build",
        "isDefault": true
    }
}

需要关注到这段代码

"command": "g++",
    "args": [
        "-g", 
        "${file}", 
        "-o", 
        "${fileBasenameNoExtension}.o",
    ],// 编译命令参数

这就是g++编译命令,要注意最后一个参数" f i l e B a s e n a m e N o E x t e n s i o n . o " , , 必 须 跟 l a u n c h . j s o n 中 p r o g r a m 参 数 ( " {fileBasenameNoExtension}.o",,必须跟launch.json中program参数(" fileBasenameNoExtension.o",launch.jsonprogram("{workspaceFolder}/${fileBasenameNoExtension}.o")的文件名相对应。还有一点就是,如果要设置label参数的话,要将之设置为preLaunchTask的值。不记得preLaunchTask回头看看launch.json。这部分通用的C++编译运行设置就OK了,现在你可以愉快地用vscode写一波hello world。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值