Linux下VSCode配置C / C++

1 安装插件

C / C++

2 配置include

出现“#include errors detected.”时,按ctrl + .跳转进入配置,或者打开c_cpp_properties.json直接配置:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                // add following lines
                "/usr/include/",
                "/usr/local/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

3 配置工程下多cpp文件

默认项目中只编译当前cpp(main),如果你是分多个cpp文件写的,会提示“undefined reference to ...”

需要修改task.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                // "${file}", 修改为下面这行
                "${fileDirname}/*.cpp",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *