Visual Studio Code 配置 mingw-w64的 GCC c + + 编译器(g + +)和 GDB 调试器 Windows 教程
机器翻译
官方链接:https://code.visualstudio.com/docs/cpp/config-mingw
Using GCC with MinGW
使用 GCC 和 MinGW
In this tutorial, you configure Visual Studio Code to use the GCC C++ compiler (g++) and GDB debugger from mingw-w64 to create programs that run on Windows.
在本教程中,您将 Visual Studio Code 配置为使用来自 mingw-w64的 GCC c + + 编译器(g + +)和 GDB 调试器来创建在 Windows 上运行的程序。
After configuring VS Code, you will compile and debug a simple Hello World program in VS Code. This tutorial does not teach you about GCC, GDB, Mingw-w64, or the C++ language. For those subjects, there are many good resources available on the Web.
在配置了 VS 代码之后,您将用 VS 代码编译和调试一个简单的 Hello World 程序。本教程不教授 GCC、 GDB、 mingw-w64或 c + + 语言。对于这些主题,网上有许多很好的资源。
If you have any problems, feel free to file an issue for this tutorial in the VS Code documentation repository.
如果您有任何问题,请随意将本教程的问题归档到 VS 代码文档存储库中。
Prerequisites 先决条件#
To successfully complete this tutorial, you must do the following steps:
要成功完成本教程,您必须执行以下步骤:
-
Install Visual Studio Code.
安装 Visual Studio 代码。
-
Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X).
为 VS 代码安装 c/c + + 扩展。您可以通过在 Extensions 视图中搜索“ c + +”(Ctrl + Shift + x)来安装 c/c + + 扩展。
-
Get the latest version of Mingw-w64 via MSYS2, which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries. Click here to download the MSYS2 installer. Then follow the instructions on the MSYS2 website to install Mingw-w64.
通过 msys2获得最新版本的 Mingw-w64,它提供了最新的 GCC、 mingw-w64和其他有用的 c + + 工具和库。点击这里下载 msys2安装程序。然后按照 msys2网站上的说明安装 Mingw-w64。
-
Add the path to your Mingw-w64
bin
folder to the WindowsPATH
environment variable by using the following steps:使用以下步骤将 Mingw-w64 bin 文件夹的路径添加到 Windows PATH 环境变量文件夹中:
- In the Windows search bar, type 'settings' to open your Windows Settings. 在 Windows 搜索栏中,键入“设置”以打开 Windows 设置
- Search for 搜寻Edit environment variables for your account 为您的帐户编辑环境变量.
- Choose the 选择
Path
variable and then select 变量,然后选择Edit 编辑. - Select 选择New 新 and add the Mingw-w64 destination folder path to the system path. The exact path depends on which version of Mingw-w64 you have installed and where you installed it. If you used the settings above to install Mingw-w64, then add this to the path: 并将 mingw-w64目标文件夹路径添加到系统路径。确切的路径取决于您安装了哪个版本的 Mingw-w64,以及安装它的位置。如果你使用上面的设置来安装 Mingw-w64,那么把它添加到路径:
C:\msys64\mingw64\bin
. - Select 选择OK 好的 to save the updated PATH. You will need to reopen any console windows for the new PATH location to be available. 保存更新后的 PATH。您需要重新打开任何控制台窗口,以便新的 PATH 位置可用
Check your MinGW installation 检查您的 MinGW 安装#
To check that your Mingw-w64 tools are correctly installed and available, open a new Command Prompt and type:
要检查您的 mingw-w64工具是否正确安装和可用,请打开一个新的命令提示符并键入:
g++ --version
gdb --version
If you don't see the expected output or g++
or gdb
is not a recognized command, make sure your PATH entry matches the Mingw-w64 binary location where the compilers are located. If the compilers do not exist at that PATH entry, make sure you followed the instructions on the MSYS2 website to install Mingw-w64.
如果您没有看到预期的输出,或者 g + + 或 gdb 不是一个可识别的命令,请确保您的 PATH 条目与编译器所在的 mingw-w64二进制位置匹配。如果 PATH 条目中不存在编译器,请确保按照 msys2网站上的说明安装 Mingw-w64。
Create Hello World 创建 Hello World#
From a Windows command prompt, create an empty folder called projects
where you can place all your VS Code projects. Then create a sub-folder called helloworld
, navigate into it, and open VS Code in that folder by entering the following commands:
在一个命令提示符文件夹中,创建一个名为项目的空文件夹,在这个文件夹中你可以放置所有的 VS 代码项目。然后创建一个名为 helloworld 的子文件夹,导航到该文件夹,并通过输入以下命令打开该文件夹中的 VS Code:
mkdir projects
cd projects
mkdir helloworld
cd helloworld
code .
The "code ." command opens VS Code in the current working folder, which becomes your "workspace". As you go through the tutorial, you will see three files created in a .vscode
folder in the workspace:
代码。”命令在当前工作文件夹中打开 VS 代码,该文件夹成为您的“工作区”。在阅读本教程时,您将看到在。工作区中的 vscode 文件夹:
tasks.json
(build instructions) (构建说明)launch.json
(debugger settings) (调试器设置)c_cpp_properties.json
(compiler path and IntelliSense settings) (编译器路径和 IntelliSense 设置)
Add a source code file 添加源代码文件#
In the File Explorer title bar, select the New File button and name the file helloworld.cpp
.
在 File Explorer 标题栏中,选择 New File 按钮并将文件命名为 helloworld.cpp。
Add hello world source code 添加 hello world 源代码#
Now paste in this source code:
现在粘贴下面的源代码:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
Now press Ctrl+S to save the file. Notice how the file you just added appears in the File Explorer view (Ctrl+Shift+E) in the side bar of VS Code:
现在按 Ctrl + s 来保存文件。注意你刚刚添加的文件是如何出现在 VS Code 边栏的 File Explorer 视图(Ctrl + Shift + e)中的:
You can also enable Auto Save to automatically save your file changes, by checking Auto Save in the main File menu.
您也可以启用自动保存,以自动保存您的文件更改,通过检查自动保存在主文件菜单。
The Activity Bar on the far left lets you open different views such as Search, Source Control, and Run. You'll look at the Run view later in this tutorial. You can find out more about the other views in the VS Code User Interface documentation.
最左边的活动栏允许您打开不同的视图,如搜索、源代码管理和运行。您将在本教程的后面看到 Run 视图。您可以在 VS 代码用户界面文档中找到关于其他视图的更多信息。
Note: When you save or open a C++ file, you may see a notification from the C/C++ extension about the availability of an Insiders version, which lets you test new features and fixes. You can ignore this notification by selecting the
X
(Clear Notification).注意: 当您保存或打开一个 c + + 文件时,您可能会看到来自 c/c + + 扩展的关于内部版本可用性的通知,它允许您测试新的特性和修复。可以通过选择 x (清除通知)来忽略此通知。
Explore IntelliSense 探索智能感知#
In your new helloworld.cpp
file, hover over vector
or string
to see type information. After the declaration of the msg
variable, start typing msg.
as you would when calling a member function. You should immediately see a completion list that shows all the member functions, and a window that shows the type information for the msg
object:
在新的 helloworld.cpp 文件中,将鼠标悬停在 vector 或 string 上以查看类型信息。在声明 msg 变量之后,开始键入 msg。就像调用成员函数一样。您应该立即看到一个完成列表,显示所有成员函数,以及一个窗口,显示 msg 对象的类型信息:
You can press the Tab key to insert the selected member; then, when you add the opening parenthesis, you will see information about any arguments that the function requires.
您可以按 Tab 键插入选定的成员; 然后,当您添加开始括号时,您将看到有关函数所需的任何参数的信息。
Build helloworld.cpp#
Next, you'll create a tasks.json
file to tell VS Code how to build (compile) the program. This task will invoke the g++ compiler to create an executable file based on the source code.
接下来,您将创建一个 tasks.json 文件来告诉 VS 代码如何构建(编译)程序。此任务将调用 g + + 编译器,以基于源代码创建可执行文件。
From the main menu, choose Terminal > Configure Default Build Task. In the dropdown, which will display a tasks dropdown listing various predefined build tasks for C++ compilers. Choose g++.exe build active file, which will build the file that is currently displayed (active) in the editor.
从主菜单中,选择终端 > 配置默认生成任务。在下拉列表中,它将显示一个任务下拉列表,列出 c + + 编译器的各种预定义的构建任务。选择 g + + 。Exe 生成活动文件,该文件将生成当前在编辑器中显示(活动)的文件。
This will create a tasks.json
file in a .vscode
folder and open it in the editor.
这将在.vscode 文件夹中创建 tasks.json 文件,并在编辑器中打开它。
Your new tasks.json
file should look similar to the JSON below:
您的新 tasks.JSON 文件看起来应该类似于下面的 JSON:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:/msys64/mingw64/bin/g++.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:/msys64/mingw64/bin/g++.exe"
}
],
"version": "2.0.0"
}
The command
setting specifies the program to run; in this case that is g++. The args
array specifies the command-line arguments that will be passed to g++. These arguments must be specified in the order expected by the compiler. This task tells g++ to take the active file (${file}
), compile it, and create an executable file in the current directory (${fileDirname}
) with the same name as the active file but with the .exe
extension (${fileBasenameNoExtension}.exe
), resulting in helloworld.exe
for our example.
命令设置指定要运行的程序; 在本例中是 g + + 。Args 数组指定将传递给 g + + 的命令行参数。这些参数必须按编译器期望的顺序指定。这个任务告诉 g + + 获取活动文件(\({ file }) ,对其进行编译,并在工作目录文件中创建一个与活动文件同名的可执行文件(\){ fileDirname })。Exe 扩展(${ fileBasenameNoExtension })。Exe) ,导致 helloworld.exe 为我们的示例。
Note: You can learn more about
tasks.json
variables in the variables reference.注意: 您可以在变量引用中了解更多关于 tasks.json 变量的信息。
The label
value is what you will see in the tasks list; you can name this whatever you like.
标签值就是您将在任务列表中看到的内容; 您可以随心所欲地命名它。
The "isDefault": true
value in the group
object specifies that this task will be run when you press Ctrl+Shift+B. This property is for convenience only; if you set it to false, you can still run it from the Terminal menu with Tasks: Run Build Task.
Group 对象中的“ isDefault”: true value 指定当您按下 Ctrl + Shift + b 时将运行此任务。此属性仅为方便起见; 如果将其设置为 false,仍然可以在终端菜单中使用 Tasks: Run Build Task 运行它。
Running the build 运行构建#
-
Go back to
helloworld.cpp
. Your task builds the active file and you want to buildhelloworld.cpp
.返回到 helloworld.cpp,您的任务构建活动文件,并希望构建 helloworld.cpp。
-
To run the build task defined in
tasks.json
, press Ctrl+Shift+B or from the Terminal main menu choose Run Build Task.要运行 tasks. json 中定义的构建任务,请按 Ctrl + Shift + b 或从终端主菜单中选择 Run Build Task。
-
When the task starts, you should see the Integrated Terminal panel appear below the source code editor. After the task completes, the terminal shows output from the compiler that indicates whether the build succeeded or failed. For a successful g++ build, the output looks something like this:
当任务启动时,您应该会看到集成终端面板出现在源代码编辑器下方。任务完成后,终端显示编译器的输出,指示生成是成功还是失败。对于一个成功的 g + + 构建,输出如下:
-
Create a new terminal using the + button and you'll have a new terminal with the
helloworld
folder as the working directory. Rundir
and you should now see the executablehelloworld.exe
.创建一个新的终端使用 + 按钮,你将有一个新的终端与 helloworld 文件夹作为工作目录。运行 dir,现在应该会看到可执行的 helloworld.exe。
-
You can run
helloworld
in the terminal by typinghelloworld.exe
(or.\helloworld.exe
if you use a PowerShell terminal).可以通过键入 helloworld.exe (如果使用 PowerShell 终端,则可以键入.helloworld.exe)在终端中运行 helloworld。
Note: You might need to press Enter a couple of times initially to see the PowerShell prompt in the terminal. This issue should be fixed in a future release of Windows.
注意: 一开始您可能需要按回车几次,才能在终端中看到 PowerShell 提示符。这个问题应该在未来的 Windows 版本中得到解决。
Modifying tasks.json#
You can modify your tasks.json
to build multiple C++ files by using an argument like "${workspaceFolder}\\*.cpp"
instead of ${file}
. This will build all .cpp
files in your current folder. You can also modify the output filename by replacing "${fileDirname}\\${fileBasenameNoExtension}.exe"
with a hard-coded filename (for example "${workspaceFolder}\\myProgram.exe"
).
您可以使用“ ${ worksomatoolder } *”这样的参数修改 tasks.json 以构建多个 c + + 文件。而不是 ${ file }。这将建立所有。当前文件夹中的 cpp 文件。还可以通过替换“ ${ fileDirname } ${ fileBasenameNoExtension }来修改输出文件名。Exe 文件名(例如“ ${ worksomatoolder } myProgram.exe.exe”)。
Debug helloworld.cpp#
Next, you'll create a launch.json
file to configure VS Code to launch the GDB debugger when you press F5 to debug the program.
接下来,您将创建一个 launch.json 文件来配置 VS Code,以便在按 f5调试程序时启动 GDB 调试器。
- From the main menu, choose 从主菜单中选择Run 快跑 > Add Configuration... 添加配置.. and then choose 然后选择C++ (GDB/LLDB) C + + (GDB/ldb).
- You'll then see a dropdown for various predefined debugging configurations. Choose 然后您将看到各种预定义调试配置的下拉列表g++.exe build and debug active file.
VS Code creates a launch.json
file, opens it in the editor, and builds and runs 'helloworld'.
VS Code 创建一个 launch.json 文件,在编辑器中打开它,构建并运行“ helloworld”。
{
"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": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
The program
setting specifies the program you want to debug. Here it is set to the active file folder ${fileDirname}
and active filename with the .exe
extension ${fileBasenameNoExtension}.exe
, which if helloworld.cpp
is the active file will be helloworld.exe
.
程序设置指定要调试的程序。在这里,它被设置为活动文件夹 ${ fileDirname }和带有。扩展名 ${ fileBasenameNoExtension }。Exe,如果 helloworld.cpp 是活动文件,则该文件将为 helloworld.exe。
By default, the C++ extension won't add any breakpoints to your source code and the stopAtEntry
value is set to false
.
默认情况下,c + + 扩展不会向源代码添加任何断点,而 stopAtEntry 值设置为 false。
Change the stopAtEntry
value to true
to cause the debugger to stop on the main
method when you start debugging.
将 stopAtEntry 值更改为 true,以便在开始调试时使调试器在 main 方法上停止。
Note: The
preLaunchTask
setting is used to specify task to be executed before launch. Make sure it is consistent with thetasks.json
filelabel
setting.注意: preLaunchTask 设置用于指定启动前要执行的任务。确保它与 tasks.json 文件标签设置一致。
Start a debugging session 启动调试会话#
- Go back to 回到
helloworld.cpp
so that it is the active file. 所以它就是活动文件 - Press 新闻稿F5 or from the main menu choose 或者从主菜单中选择Run > Start Debugging 运行 > 开始调试. Before you start stepping through the source code, let's take a moment to notice several changes in the user interface: .在你开始介绍源代码之前,让我们花点时间注意一下用户界面的几个变化:
-
The Integrated Terminal appears at the bottom of the source code editor. In the Debug Output tab, you see output that indicates the debugger is up and running.
集成终端显示在源代码编辑器的底部。在“调试输出”选项卡中,可以看到指示调试器已启动并正在运行的输出。
-
The editor highlights the first statement in the
main
method. This is a breakpoint that the C++ extension automatically sets for you:编辑器突出显示 main 方法中的第一条语句。这个断点是 c + + 扩展自动为你设置的:
-
The Run view on the left shows debugging information. You'll see an example later in the tutorial.
左边的 Run 视图显示了调试信息。
-
At the top of the code editor, a debugging control panel appears. You can move this around the screen by grabbing the dots on the left side.
在代码编辑器的顶部,将出现一个调试控制面板。你可以通过抓取屏幕左边的点来移动它。
Step through the code 逐步完成代码#
Now you're ready to start stepping through the code.
现在您已经准备好开始逐步执行代码了。
-
Click or press the Step over icon in the debugging control panel.
单击或按下调试控制面板中的 Step over 图标。
This will advance program execution to the first line of the for loop, and skip over all the internal function calls within the
vector
andstring
classes that are invoked when themsg
variable is created and initialized. Notice the change in the Variables window on the left.这将把程序执行提前到 for 循环的第一行,并跳过创建和初始化 msg 变量时在 vector 和 string 类中调用的所有内部函数调用。注意左侧 Variables 窗口中的变化。
In this case, the errors are expected because, although the variable names for the loop are now visible to the debugger, the statement has not executed yet, so there is nothing to read at this point. The contents of
msg
are visible, however, because that statement has completed.在这种情况下,预计会出现错误,因为尽管调试器现在可以看到循环的变量名,但语句尚未执行,因此此时没有什么可读的内容。但是,msg 的内容是可见的,因为该语句已经完成。
-
Press Step over again to advance to the next statement in this program (skipping over all the internal code that is executed to initialize the loop). Now, the Variables window shows information about the loop variables.
再次按“步骤”以前进到此程序中的下一个语句(跳过为初始化循环而执行的所有内部代码)。现在,Variables 窗口显示有关循环变量的信息。
-
Press Step over again to execute the
cout
statement. (Note that as of the March 2019 release, the C++ extension does not print any output to the Debug Console until the loop exits.)再次按“步骤”以执行 cout 语句。(请注意,在2019年3月的版本中,c + + 扩展在循环退出之前不会将任何输出打印到 Debug 控制台。)
-
If you like, you can keep pressing Step over until all the words in the vector have been printed to the console. But if you are curious, try pressing the Step Into button to step through source code in the C++ standard library!
如果愿意,可以继续按下 Step,直到向量中的所有单词都打印到控制台。但是如果你好奇的话,可以试着按下 Step Into 按钮来逐步查看 C++标准程式库中的源代码!
To return to your own code, one way is to keep pressing Step over. Another way is to set a breakpoint in your code by switching to the
helloworld.cpp
tab in the code editor, putting the insertion point somewhere on thecout
statement inside the loop, and pressing F9. A red dot appears in the gutter on the left to indicate that a breakpoint has been set on this line.要返回到自己的代码,一种方法是继续按下“步骤”。另一种方法是在代码中设置断点,方法是切换到代码编辑器中的 helloworld.cpp 选项卡,将插入点放在循环中 cout 语句的某个位置,然后按 F9。左边的 gutter 中出现一个红点,表示在此行上设置了断点。
Then press F5 to start execution from the current line in the standard library header. Execution will break on
cout
. If you like, you can press F9 again to toggle off the breakpoint.然后按 f5从标准库头中的当前行开始执行。执行将在结束时终止。如果愿意,可以再次按 f9以关闭断点。
When the loop has completed, you can see the output in the Integrated Terminal, along with some other diagnostic information that is output by GDB.
循环完成后,您可以看到集成终端中的输出,以及 GDB 输出的其他诊断信息。
Set a watch 设置一个手表#
Sometimes you might want to keep track of the value of a variable as your program executes. You can do this by setting a watch on the variable.
有时您可能希望在程序执行时跟踪变量的值。你可以通过在变量上设置一个表来实现这一点。
-
Place the insertion point inside the loop. In the Watch window, click the plus sign and in the text box, type
word
, which is the name of the loop variable. Now view the Watch window as you step through the loop.将插入点放在循环中。在“监视”窗口中,单击加号,并在文本框中键入 word,这是循环变量的名称。现在在循环中单步执行时查看“监视”窗口。
-
Add another watch by adding this statement before the loop:
int i = 0;
. Then, inside the loop, add this statement:++i;
. Now add a watch fori
as you did in the previous step.通过在循环之前添加以下语句来添加另一个 watch: int i = 0; 。然后,在循环中,添加以下语句: + + i; 。现在为 i 添加一个手表,如上一步所做的那样。
-
To quickly view the value of any variable while execution is paused on a breakpoint, you can hover over it with the mouse pointer.
若要在断点上暂停执行时快速查看任何变量的值,可以使用鼠标指针将鼠标悬停在该变量上。
C/C++ configurations C/c + + 配置#
If you want more control over the C/C++ extension, you can create a c_cpp_properties.json
file, which will allow you to change settings such as the path to the compiler, include paths, C++ standard (default is C++17), and more.
如果您希望对 c/c + + 扩展有更多的控制权,可以创建一个 c _ cpp _ properties。Json 文件,它允许您更改设置,例如编译器的路径,include 路径,c + + 标准(默认是 c + + 17) ,等等。
You can view the C/C++ configuration UI by running the command C/C++: Edit Configurations (UI) from the Command Palette (Ctrl+Shift+P).
您可以通过运行命令 c/c + + : Edit Configurations (UI)从 Command Palette (Ctrl + Shift + p)查看 c/c + + configuration UI。
This opens the C/C++ Configurations page. When you make changes here, VS Code writes them to a file called c_cpp_properties.json
in the .vscode
folder.
这将打开 c/c + + Configurations 页面。当您在这里进行更改时,VS Code 将它们写入一个名为 c_cpp _ properties 的文件中。杰森在。Vscode 文件夹。
Here, we've changed the Configuration name to GCC, set the Compiler path dropdown to the g++ compiler, and the IntelliSense mode to match the compiler (gcc-x64)
这里,我们将 Configuration 名称更改为 GCC,将 Compiler 路径下拉到 g + + 编译器,将 IntelliSense 模式设置为与编译器匹配(GCC-x64)
Visual Studio Code places these settings in .vscode\c_cpp_properties.json
. If you open that file directly, it should look something like this:
Visual Studio Code 将这些设置放在. vscode c _ cpp _ properties. json 中,如果直接打开该文件,它应该是这样的:
{
"configurations": [
{
"name": "GCC",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
You only need to add to the Include path array setting if your program includes header files that are not in your workspace or in the standard library path.
如果程序包含不在工作区或标准库路径中的头文件,则只需添加到 Include 路径数组设置。
Compiler path 编译器路径#
The extension uses the compilerPath
setting to infer the path to the C++ standard library header files. When the extension knows where to find those files, it can provide features like smart completions and Go to Definition navigation.
扩展名使用 compilerPath 设置来推断 C++标准程式库文件的路径。当扩展知道在哪里可以找到这些文件时,它可以提供智能完成和定义导航等功能。
The C/C++ extension attempts to populate compilerPath
with the default compiler location based on what it finds on your system. The extension looks in several common compiler locations.
C/c + + 扩展试图根据它在系统中发现的内容,用默认的编译器位置填充 compilerPath。该扩展查找几个常见的编译器位置。
The compilerPath
search order is:
compilerPath 搜索顺序是:
- First check for the Microsoft Visual C++ compiler 首先检查 Microsoft Visual c + + 编译器
- Then look for g++ on Windows Subsystem for Linux (WSL) 然后在 Linux (WSL)的 Windows 子系统中查找 g + +
- Then g++ for Mingw-w64. 然后用 g + + 表示 Mingw-w64
If you have Visual Studio or WSL installed, you may need to change compilerPath
to match the preferred compiler for your project. For example, if you installed Mingw-w64 version 8.1.0 using the i686 architecture, Win32 threading, and sjlj exception handling install options, the path would look like this: C:\Program Files (x86)\mingw-w64\i686-8.1.0-win32-sjlj-rt_v6-rev0\mingw64\bin\g++.exe
.
如果安装了 visualstudio 或 WSL,则可能需要更改 compilerPath 以匹配项目的首选编译器。例如,如果您使用 i686架构、 win32线程和 sjlj 异常处理安装选项安装 Mingw-w64 version 8.1.0,那么路径如下: c: Program Files (x86) Mingw-w64 i686-8.1.0-Win32-sjlj-rt _ v6-rev0 mingw64 bin g + + 。执行。
Troubleshooting 故障排除#
MSYS2 is installed, but g++ and gdb are still not found 已经安装了 MSYS2,但是仍然没有找到 g + + 和 gdb#
You must follow the steps on the MSYS2 website and use the MSYS CLI to install Mingw-w64, which contains those tools.
您必须遵循 msys2网站上的步骤,并使用 MSYS CLI 安装 Mingw-w64,其中包含这些工具。