参考:https://code.visualstudio.com/docs/cpp/config-mingw

前提条件:

进行环境配置之前请先做好以下工作

1、安装vscode

2、安装 c++ extension for VS Code (https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

3、安装mingw-w64。注意安装路径不能有空格。比如可以安装到 d:\Mingw-w64

4、将Minge-w64的bin文件夹路径添加到windows的PATH环境变量里。比如我的路径是 c:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin

在vscode中创建工作区

方式1:点击菜单“文件”->“打开文件夹”,选择一个文件夹(比如project1),则文件夹project1就变成当前工作区。

方式2:

在命令行执行以下命令

 

mkdir helloworld
cd helloworld
code .

 

hellowork目录就成了当前工作区。  

 

配置完成后会在工作区文件夹生成下面的文件

 

  • c_cpp_properties.json (compiler path and IntelliSense settings)(编译器路径和智能感知设置)
  • tasks.json (build instructions)(生成说明)
  • launch.json (debugger settings)(调试设置)

设置编译器路径

按 Ctrl+Shift+P,打开命令面板

在弹出的窗口中输入 C/C++,在弹出的列表中选择“Edit Configurations (UI)”,然后系统会打开C/C++ IntelliSense Configurations 页面。在此页面所做的修改会被保存到文件c_cpp_properties.json

将编译器路径修改为上面安装的mingw-w64的路径(D:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe)

将IntelliSense 模式修改为 gcc-x64

我配置出来的文件是这样的

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "D:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "compilerArgs": [],
            "browse": {
                "path": [
                    "${workspaceFolder}/**"
                ],
                "limitSymbolsToIncludedHeaders": true
            }
        }
        
    ],
    "version": 4
}
.vscode/c_cpp_properties.json

相关文章:

  • 2021-08-06
  • 2021-05-24
  • 2021-11-05
  • 2021-10-12
  • 2021-08-15
  • 2021-09-02
  • 2021-07-24
  • 2021-10-30
猜你喜欢
  • 2021-09-28
  • 2021-05-15
  • 2021-04-01
  • 2022-02-01
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案