VS Code 安裝環境配置

參考鏈接:https://www.cnblogs.com/bpf-1024/p/11597000.html

C/C++環境搭建

1.安裝好VS Code ,這個比較簡單,網上的教程也很多

2.安裝MinGW的C/C++編譯環境(MinGW64下載

   不要直接點Download latest Version,往下拉找到  x86_64-win32-seh 下載解壓放到自己想放的路徑就行了

   然後就是系統變量的配置  D:\Program Files\MinGW\bin   我的路徑是這樣,請根據自己的情況配置

3.VS Code編輯器的配置路徑

(默認使用是Microsoft C ++(MSVC)編譯器,防止找不到頭文件)我試到的方法是以下配置解決的,也可以自己網上找(MSVC)編譯器配置方式

根據平臺的不同,用戶配置變量文件分別在以下位置:

        Windows %APPDATA%\Code\User\settings.json

        macOS $HOME/Library/Application Support/Code/User/settings.json

        Linux $HOME/.config/Code/User/settings.json

工作區置文件位於根文件夾中的.vscode文件夾下。

VS Code 配置參考文檔:https://code.visualstudio.com/docs/getstarted/settings

4.C++文件配置

  在工程的目錄下創建一個文件夾.vscode

文件夾下創建三個文件launch.json  , settings.json  ,tasks.json

launch.json
 

/*
    VSCode portable launch.json for c++ GDB debug By blackkitty
*/

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team        
// ${file}: the current opened file                     
// ${fileBasename}: the current opened file's basename 
// ${fileDirname}: the current opened file's dirname    
// ${fileExtname}: the current opened file's extension  
// ${cwd}: the current working directory of the spawned process
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch (GDB)",
            "preLaunchTask": "build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/Program Files/MinGW/bin/gdb.exe", //修改自己的路徑
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }]
}

settings.json 

{
    "files.associations": {
        "iostream": "cpp",
        "ostream": "cpp",
        "cmath": "cpp",
        "array": "cpp",
        "chrono": "cpp",
        "functional": "cpp",
        "ratio": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "future": "cpp",
        "streambuf": "cpp",
        "sstream": "cpp",
        "initializer_list": "cpp",
        "valarray": "cpp"
    }
}

tasks.json

/*
    VSCode portable tasks.json for c++ GDB debug By blackkitty
*/

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team        
// ${file}: the current opened file                     
// ${fileBasename}: the current opened file's basename 
// ${fileDirname}: the current opened file's dirname    
// ${fileExtname}: the current opened file's extension  
// ${cwd}: the current working directory of the spawned process

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "windows": {
                "command": "g++",
                "args": [
                    "-ggdb",
                    "\"${file}\"",
                    "--std=c++11",
                    "-o",
                    "\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
                ]
            }
        }
    ]
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章