Vscode编译构建C++

linux

  1. 首先安装好g++
  2. 编写好文件main.cpp
  3. 编译文件,需要构建tasks.json;用来编译

我的比较简单的

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "args": [
                "*.cpp",
                "-o",
                "a.out"
     
            ]
        }
    ]
}

详细的

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true  // 默认生成任务,即按“Ctrl+Shift+B”快捷键会自动运行的任务
            }, 
            "linux": {
                "command": "g++",
                "args": [
                    "-g",           // 生成调试信息
                    "-Wall",        // 开启所有警告
                    "*.cpp",        // 编译所cpp文件
                    "-lpthread",    // 链接pthread库(Linux系统必需) 
                    "--std=c++11",  // 使用C++11标准 
                    "-o",
                    "paralle_for_each.out" // 指定输出文件名
                ]
            }, 
            "problemMatcher": {
                "owner": "cc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            } 
            
        } 
    ]
}


4.点到蜘蛛那里,运行,然后会让你构建一个launch.json;修改其中一行
"program": "${workspaceFolder}/a.out",

我的

{
    // 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}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

详细的

{
    // 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}/paralle_for_each.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
  1. 接着终端窗口就会弹出运行结果
发布了20 篇原创文章 · 获赞 49 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/O_MMMM_O/article/details/100981118
今日推荐