C++ 如何添加g++;从MinGW到PATH

C++ 如何添加g++;从MinGW到PATH,c++,g++,visual-studio-code,mingw,C++,G++,Visual Studio Code,Mingw,我在Windows 10上使用Visual Studio代码,并尝试使用MinGW的g++构建一个程序(从源文件Bus.cpp名为Bus)。我使用从以前的线程中读取的各种方法修改了tasks.json文件。我提供了tasks.json文件的屏幕截图以及构建后的结果(ctrl+shift+b)。我也在下面提供我的问题 问题1)我希望能够使用方法1构建和创建一个名为“总线”的程序。然而,我必须用MinGW的g++编译器的目录路径替换“g++”(如方法2所示)。我要怎么做才能把“g++”放在M

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

问题1)我希望能够使用方法1构建和创建一个名为“总线”的程序。然而,我必须用MinGW的g++编译器的目录路径替换“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
            }
        }
    ]
}
{
    // 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
            }
        }
    ]
}
{
    // 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: 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.
> 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.
    > 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.
第二种方法产生的输出:

> 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.
> 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.
    > 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.
第四种方法产生的输出:

> 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.
> 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.
    > 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.
>执行任务:C:/MinGW/bin/g++-g bus.cpp<
终端进程终止,退出代码为:1
终端将被任务重用,请按任意键将其关闭。

总而言之,您需要将
mingW gcc
添加到您的路径中

最简单的方法:

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


在末尾添加分号后,将目录添加到
路径
变量。

请不要将文本或代码作为图片发布!很抱歉,我通常不这样做,但我这样做是为了为每个方法显示三件事:整个tasks.json文件、结果输出和VS代码中的explorer侧栏,显示可执行程序确实没有创建。我会编辑它。