十分钟搭建VScode C/C++运行环境

一、下载配置vscode

1.下载安装VScode

 地址:https://code.visualstudio.com/download

  1. 下载后,运行安装程序 (VSCodeUserSetup-{version}.exe)。这只需要一分钟。
  2. 安装程序会将 Visual Studio Code 添加到环境变量中%,可以使用CMD键入“code”打开VS Code验证

 2、配置vscode

安装VS Code 的 C/C++ 扩展您可以通过在扩展视图 ( Ctrl+Shift+X )中搜索“C++”来安装 C/C++ 扩展。

C/C++ 扩展

 二、安装 MinGW-w64 工具链

1、下载MinGW-w64

获取最新版本的MinGW-w64:MSYS2官网,可以从 MSYS2 官网页面下载最新的安装程序或使用此安装程序的直接链接

2、MSYS2配置优势

它提供最新的GCC、MinGW-w64和其他有用的C工具和库的本地构建。这将提供必要的工具来编译代码。这将提供必要的工具来编译代码、调试代码并配置它以使用微软的自动补全技术

运行安装程序并按照安装向导的步骤进行操作。请注意,MSYS2 需要 64 位 

3、MSYS2配置方法

1、双击MSYS2,进行安装。

在向导中,选择所需的安装文件夹。记录此目录以备以后使用

2、安装完成后打开MSYS2,输入下面命令

Run MSYS2 now框并选择Finish。这将为您打开一个MSYS2终端窗口。

pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain

3、按Enter接受组中默认的包数。

MYSS2 安装程序

4、当提示是否继续安装时输入“Y”

5、添加环境变量

msys安装目录下的ucrt64\bin添加到系统的环境变量

6、检查您的 MinGW 安装

打开CMD输入下面命令,出现版本号表明配置成功

gcc --version
g++ --version
gdb --version

 三、测试效果

1、运行一个C++程序(ctrl+alt+N运行程序)

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!11"};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
}

 2、运行一个C语言程序(ctrl+alt+N运行程序)

#include <stdio.h>
int main()
{
    printf("hello C Word from vs code");
    return 0;
}

vscode更多内容:

探索调试器

 故障排除

猜你喜欢

转载自blog.csdn.net/qq_43445867/article/details/134653175