C++(27)-windows-VSCODE+C++---cl.exe

本文详细介绍了如何在Visual Studio Code(VSCODE)中下载并配置MinGW,设置C++环境,以及将cl.exe编译器添加到环境变量。步骤包括下载VSCODE和MinGW,配置环境变量,设置编译环境,并解决调试权限问题。同时提供了launch.json, tasks.json和c_cpp_properties.json的配置示例,以便于在VSCode中顺利进行C++程序的编写和调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载VSCODE
2.下载MinGW
3.配置C++环境
4.配置编译环境(cl.exe)
5.测试程序

 


1.下载安装VSCODE
        
https://code.visualstudio.com/
2.下载安装MinGW
     下载 
mingw.org  一般不要选择下午,速度慢还老出错。凌晨会是个不错的时间段:)
     2.1 安装选项:
       
     点击apply
      

     出现
      
     表示安装好了。
  2.2 配置环境变量
     
D:\MinGW\bin
      
   命令行 gcc -v出现下图表示可以了
    
    
3.配置C++环境
    CTRL+SHIF+P
     

    选择UI的。 写C :选择GCC 写C++:选择G++ 或者cl.exe
     
4.配置编译环境(cl.exe)

    cl.exe是Microsoft C/C++编译器 ,一般用VS打开,如果想在VSCode下用:
4.1.把cl.exe配置成环境变量。
      

//1.在Path中添加cl.exe所在文件夹路径。若未找到,直接VS的安装目录下搜索cl.exe即可
D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64;

//2.在系统变量中新建变量INCLUDE,添加cl.exe的包含目录
D:\Program Files\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include;


//3.在系统变量中新建变量LIB,添加cl.exe的库目录
D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\lib\x86;

当出现下图时表明OK了

      
4.2.设置权限
      直接调试时会出现
      

   解决方法1. 通过X86 Native Tools Command Prompt或者X64 Native Tools Command PromptVS开发人员的权限打开VS Code。
        
 

D:\Program Files (x86)\Microsoft Visual Studio\2019\Community> code D:\01C++11\VSCODE\

解决方法2:   通过Developer Command Prompt for VS 2017VS开发人员的权限打开VS Code。

解决方法3:   调试时,选择C++ (Windows)*和*默认配置将上面的launch.json和tasks.json拷贝到.vscode文件夹中。
4.3launch.json
   

{
    // 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": "cl.exe - 生成和调试活动文件",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "preLaunchTask": "C/C++: cl.exe build active file"
        }
    ]
}

task.json
 

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Generated task by Debugger"
        }
    ],
    "version": "2.0.0"
}

c_cpp_properties.json
 

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}


5.测试程序
  


#include <iostream>
#include<stdlib.h>
using namespace std;

int main()
{
   cout<<"hello"<<endl;
   system("pause");
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值