天天看點

vscode用dev配置c/c++

三步利用dev-cpp配置c/c++環境

1.、dev

找到devc 內建的mingw路徑,添加環境變量(cmd輸入gcc -v檢測環境是否添加)

通常為: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin

2、vs code

需要擴充:C/C++; code runner ;

vscode用dev配置c/c++
vscode用dev配置c/c++

3、配置

自定義檔案夾.vscode

創立launch.json、tasks.json、c_cpp_properties.json三個檔案

● launch.json

{{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 啟動",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",//指預設檔案操作的目錄(如fopen的預設尋找位置),現在是c檔案的目錄,修改為${workspaceFolder}就是工作檔案夾目錄
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gdb.exe",//路徑要修改
            "setupCommands": [
                {
                    "description": "為 gdb 啟用整齊列印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe 生成活動檔案"
        }
    ]
}}
           

● tasks.json

{
    "version": "2.0.0",
    "command": "gcc",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${file}.exe"
    ], // 編譯指令參數
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceRoot}"
        ],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    },
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "new",
        "showReuseMessage": true,
        "clear": false
    },
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe 生成活動檔案",
            "command": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gcc.exe",//路徑要修改
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin"//路徑要修改
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "編譯器: \"C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gcc.exe"//路徑要修改
        }
    ]
}
           

● c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",            
                "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++",
                "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32",
                "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward",
                "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include",
                "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include",
                "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed",
                "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include"
    //路徑要修改
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gcc.exe",//路徑要修改
            "cStandard": "c99",
            "cppStandard": "c++98",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
           
  • 注:代碼來自知乎 3BPM

繼續閱讀