十六、windows11下VSCode配置C/C++编译环境

  • 1.安装VSCode
  • 2.中文插件
  • 3.MinGW编译器下载和配置
  • 4.VSCode配置c/c++编译环境
  • 5.测试是否配置成功
  • 6.使用万能头文件 #include <bits/stdc++.h>

1.安装VSCode

下载安装




2.中文插件

3.MinGW编译器下载和配置

Windows和Ubuntu不同,Ubuntu是自带gcc的,但是Windwos并没有自带C/C++的编译器,需要自己下载

MinGW 的全称是:Minimalist GNU on Windows
它实际上是将经典的开源 C语言 编译器 GCC 移植到了 Windows 平台下,并且包含了 Win32API ,因此可以将源代码编译为可在 Windows 中运行的可执行程序。而且还可以使用一些 Windows 不具备的,Linux平台下的开发工具。一句话来概括:MinGW 就是 GCC 的 Windows 版本

MinGW-w64 与 MinGW 的区别在于 MinGW 只能编译生成32位可执行程序,而 MinGW-w64 则可以编译生成 64位 或 32位 可执行程序。正因为如此,MinGW 现已被 MinGW-w64 所取代。

下载 MinGW-w64 编译器

下载好这个压缩包之后,解压


然后将里面的文件,放到一个不含中文路径的目录,比如我这里将这些文件复制到D:\01Software\MinGW

然后复制文件里bin目录的路径(后面配置环境变量时用得到)

bin目录下的这两个可执行文件,分别是C++的编译器、C的编译器,我们就是需要这两个东西
后面安装VSCode的C/C++插件,也是去调用这两个可执行文件

然后这个 gdb.exe 就是调试器

在系统环境变量配置path变量:Win + Q,在搜索栏中输入环境变量


找到Path——编辑

新建

把下载的MinGW里的bin目录路径粘贴在这里,我的电脑是D:\01Software\MinGW\bin

检查是否配置成功

  1. 打开cmd,

  2. 进入bin目录

  3. 输入gcc -v或gcc -v或g++ -v

OK,MinGW-w64 配置成功
实际上配置环境变量的目的就是:让你更好的打开软件,和操作软件,其实如果不配置,进入到软件的安装位置,同样可以打开的,但是配置了环境变量之后,当我们需要调用这些软件时,系统会自动帮我们去寻找环境变量中的资源
所以,其实现在我们在任何一个目录下,输入 gcc -v 都是 OK 的

4.VSCode配置c/c++编译环境

下载C/C++插件

安装之后重启一下VSCode

然后我们新建一个文件夹,用于放置我们的工程,文件名cpp demo
进入这个文件夹,右键在终端打开,输入code .
即可快速在VSCode中打开这个工程

可以看到目前这个文件夹里面是空的,啥也没有

在vsCode文件夹下创建一个.vscode文件夹并创建3个文件
分别是c_cpp_properties.json,launch.json,tasks.json

然后分别复制下面的内容到这三个文件中

c_cpp_properties.json

{"configurations": [{"name": "Win32","includePath": ["${workspaceFolder}/**"],"defines": ["_DEBUG", "UNICODE", "_UNICODE"],"windowsSdkVersion": "10.0.17763.0","compilerPath": "D:\\01Software\\MinGW\\bin\\g++.exe",   /**** 修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\ ****/"cStandard": "c11","cppStandard": "c++17","intelliSenseMode": "${default}"}],"version": 4
}

launch.json

{"version": "0.2.0","configurations": [{"name": "g++.exe build and debug active file","type": "cppdbg","request": "launch","program": "${fileDirname}\\${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": true,"MIMode": "gdb","miDebuggerPath": "D:\\01Software\\MinGW\\bin\\gdb.exe",        /**** 修改成自己bin目录下的gdb.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\ ****/"setupCommands": [{"description": "为 gdb 启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "task g++"}]
}

tasks.json

{"version": "2.0.0","tasks": [{"type": "shell","label": "task g++","command": "D:\\01Software\\MinGW\\bin\\g++.exe",   /**** 修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\ ****/"args": ["-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe","-I","D:\\05cpp demo",      /**** 修改成自己放c/c++项目的文件夹,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\ ****/"-std=c++17"],"options": {"cwd": "D:\\01Software\\MinGW\\bin"    /**** 修改成自己的bin目录,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\ ****/},"problemMatcher":["$gcc"],"group": "build",}]
}

5.测试是否配置成功

新建一个helloworld.cpp,按F5运行

#include <stdio.h>
#include <windows.h>
int main()
{printf("Hello World\n");system("pause");return 0;
}

可以看到安装了插件之后,就可以调用g++.exe这个编译器了!!!很方便,不需要手动输入编译指令了

6.使用万能头文件 #include <bits/stdc++.h>

// C++ includes used for precompiling -*- C++ -*-// Copyright (C) 2003-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>./** @file stdc++.h*  This is an implementation file for a precompiled header.*/// 17.4.1.2 Headers// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cuchar>
#include <cwchar>
#include <cwctype>
#endif// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

MinGW中是自带这个万能头文件的,路径如下
D:\01Software\MinGW\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\x86_64-w64-mingw32\bits

但是在 helloworld.cpp 中直接#include <bits/stdc++.h>是用不了的,编译会报错,这是为什么呢?
打开bits/stdc++.h,我们会看到
这个头文件最后面:和网上的万能头文件相比,多了一块儿这个声明,导致报错,删除这一块儿进行了

十六、windows11下VSCode配置C/C++编译环境相关推荐

  1. VScode配置C语言编译环境

    VScode配置C语言编译环境 前言 最近学校开了c语言课,使用vc6.0来编写c语言,但vc6.0太旧,没有代码补全和代码检查功能,所以我花了很长时间配置vscode的c开发环境,由于第一次配置,花 ...

  2. vscode 配置 C/C++ 编译环境 教程

    文章目录 第一步:下载安装 第二步:环境配置 第三步 下载安装VSCode(已经装好了请跳到第四步) 第四步:安装VSCode cpp相关的插件 第五步:配置c++的.vscode文件 第六步:配置c ...

  3. vscode配置c/c++编译环境(最终解决办法)

    vscode配置c++编译环境的完美配置与问题解决 如图,博主在用vscode配置c++时出现了很多问题: 当时真的要崩溃了,我的错误提示是:preLaunchTask"Compile&qu ...

  4. ubuntu下vscode配置C++项目编译调试(json文件),以高翔octomap教程为例,顺便解决vscode无法设置断点问题.

    首先展示一下文件路径结构: 其中C++文件在src目录中,.vscode以及CMakeLists.txt在上层目录. 1.编译设置 该项目的编译是在build.sh文件中,内容就是 cd build ...

  5. vs配置编译c语言,为 VSCode 配置 C 语言编译环境

    1. 前提条件 安装 VSCode 以及 MinGW 安装好 VSCode 中的 C/C++ 扩展 [图片上传失败...(image-e93c7c-1606314000230)] PS: 我建议使用 ...

  6. C语言编译php环境,vscode中C语言编译环境的配置方法(分享)

    本篇文章给大家介绍一下vscode配置C语言编译环境的方法.有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助. vscode c语言的环境配置 完整教程请查看该教程:https://bl ...

  7. 数学之美 系列十六 (下)- 不要把所有的鸡蛋放在一个篮子里 最大熵模型

    数学之美 系列十六 (下)- 不要把所有的鸡蛋放在一个篮子里 最大熵模型 我们上次谈到用最大熵模型可以将各种信息综合在一起.我们留下一个问题没有回答,就是如何构造最大熵模型.我们已经所有的最大熵模型都 ...

  8. 数学之美 系列十六 (下)- 不要把所有的鸡蛋放在一个篮子里 最大熵模型...

    数学之美 系列十六 (下)- 不要把所有的鸡蛋放在一个篮子里 最大熵模型 我们上次谈到用最大熵模型可以将各种信息综合在一起.我们留下一个问题没有回答,就是如何构造最大熵模型.我们已经所有的最大熵模型都 ...

  9. Ubuntu下VScode配置ssh免密远程登录

    一 实现步骤 1.在本机与远程服务器上, 输入ssh-keygen -t rsa,然后连续回车直到结束 2.在本机上执行命令 ssh-copy-id 命令 (1).命令介绍 ssh-copy-id命令 ...

最新文章

  1. Elasticsearch内存分配设置详解
  2. Windows操作系统产品名与内部版本号的对应(windows版本号)
  3. 实时可视化 Debug:VS Code 开源新工具,一键解析代码结构
  4. 如何使处于不同局域网的计算机实现远程通信_小区自来水二次加压泵站远程监控系统方案...
  5. 基础佛学知识-间歇博客
  6. 如何提升应用程序启动权限
  7. 发票管理软件_企业为什么需要采购管理软件?
  8. Spring Cloud Sleuth 之Greenwich版本全攻略
  9. 蓝海灵豚发票管理系统
  10. php解析torrent文件格式,bittorrent 种子文件结构解析
  11. ubuntu14.04安装Java jdk/jdr虚拟机
  12. TypeError: __init__() got an unexpected keyword argument ‘rate‘
  13. 面试笔记-1.计算机网络面试核心
  14. Geospark电火花使用再记录
  15. 数据可视化实验一之单变量数据的统计图表可视化
  16. PT100转RS485热电阻Modbus低成本数据采集模块
  17. Voice conversion相关语音数据集综合汇总
  18. warning: LF will be replaced by CRLF in ** 的原因及解决办法
  19. vue使用addrouter添加动态路由
  20. MySQL单元选择题及答案(期末复习题)

热门文章

  1. matlab画图:坐标轴、刻度、label
  2. 832计算机专业基础,福建师范大学2020年考研832计算机应用综合考试大纲
  3. 软件测试技能大赛学习路线(更新与5月27日)
  4. 2022-2025年最新最全Java毕业设计选题Java/mysql/springboot/微信小程序
  5. 年轻人开始流行给自己买花
  6. 孤单并不可怕,怕的是一直孤单
  7. 为什么穷人越来越穷?
  8. Vmware的三种网络连接模式(bridged、NAT、host-only)区别
  9. 智哪儿讯:艾瑞联合Aqara绿米发布《中国全屋智能行业研究白皮书》
  10. 简要解析Java中的throw和throws关键字