gpt4 book ai didi

c++ - 如何将 g++ 从 MinGW 添加到 PATH

转载 作者:行者123 更新时间:2023-11-30 05:04:58 30 4
gpt4 key购买 nike

我在 Windows 10 上使用 Visual Studio Code,我正在尝试使用 MinGW 的 g++ 构建一个程序(从源文件 Bus.cpp 调用 Bus)。我使用从以前的线程中读取的各种方法修改了 tasks.json 文件。我提供了 tasks.json 文件的屏幕截图和构建后的结果 (ctrl + shift + b)。我也在下面提供我的问题。

Method 1

Method 2

Method 3

Method 4

问题 1)我希望能够使用方法 1 构建和创建一个名为“bus”的程序。但是,我必须将“g++”替换为 MinGW 的 g++ 编译器的目录路径(如方法 2 所示) .我需要做什么才能只放置“g++”而不是 MinGW 的 g++.exe 的路径?

问题 2) 看起来它是使用方法 2 和 4 编译的,它们提供了 MinGW 的 g++ 编译器的目录路径,但我没有看到名为“bus”的构建程序,即使我在命令中使用了“-o bus”。为什么我看不到呢?

编辑以显示代码:

第一种方法 tasks.json 文件:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++ -g bus.cpp -o bus",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

第一种方法产生的输出:

> Executing task: g++ -g bus.cpp -o bus <

g++ : The term 'g++' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ g++ -g bus.cpp -o bus
+ ~~~
+ CategoryInfo : ObjectNotFound: (g++:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

第二种方法tasks.json文件:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "C:/MinGW/bin/g++.exe -g bus.cpp -o bus",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

第二种方法产生的输出:

> Executing task: C:/MinGW/bin/g++.exe -g bus.cpp -o bus <

The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Third Method tasks.json file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g", "bus.cpp", "-o", "bus"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

第三种方法产生的输出:

    > Executing task: g++ -g bus.cpp -o bus <

g++ : The term 'g++' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ g++ -g bus.cpp -o bus
+ ~~~
+ CategoryInfo : ObjectNotFound: (g++:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

第四种方法tasks.json文件:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "C:/MinGW/bin/g++",
"args": [
"-g", "bus.cpp", "-o", "bus"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

第四种方法的结果输出:

    > Executing task: C:/MinGW/bin/g++ -g bus.cpp <

The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

最佳答案

总而言之,您想将 mingW-gcc 添加到您的路径中。

最简单的方法:

开始菜单 -> 计算机 -> 右键单击​​ -> 属性 -> 高级系统设置(左侧某处)-> 环境变量

然后在末尾添加分号后将您的目录添加到 Path 变量中。

关于c++ - 如何将 g++ 从 MinGW 添加到 PATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48612744/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com