gpt4 book ai didi

c++ - 'g++' 不是内部或外部命令,也不是可运行的程序或批处理文件。

转载 作者:行者123 更新时间:2023-12-02 10:24:06 28 4
gpt4 key购买 nike

我正在尝试使用 C++ Compiler 设置 VScode
按照本教程
enter link description here

我遇到的问题是(通过使用代码运行器运行代码)

'g++' is not recognized as an internal or external command, operable program or batch file. enter image description here



如果我使用调试选项运行,我就会遇到这个问题

The preLaunchTask 'build & run file' terminated with exit code 1.enter image description here



这是我的“c_cpp_properties.json”
{
"configurations": [
{
"name": "Win32",
"intelliSenseMode": "clang-x64",
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=7",
"__stdcall=attribute((stdcall))",
"__cdecl=__attribute__((__cdecl__))",
"__cplusplus=201703L"
],
"includePath": [
"${workspaceFolder}/include",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include"
],
"browse": {
"path": [
"${workspaceFolder}/include",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/backward",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed",
"C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include"
],
"limitSymbolsToIncludedHeaders": false,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4

}

这是我的“launch.json”
{
"version": "0.2.0",
"configurations": [
{
"name": "Run C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build & run file"
},
{
"name": "Debug C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build & debug file"
}
]
}

这是我的“tasks.json”
{
"version": "2.0.0",
"tasks": [
{
"label": "build & debug file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "build & run file",
"type": "shell",
"command": "g++",
"args": [
"-o",
"${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

我只是想学习C++,在网上试了很多天,还是解决不了,请大家帮忙。
谢谢你。

最佳答案

您必须将 g++ 添加到您的 PATH 变量中。

首先,找出你是否安装了g++并找到它所在的位置。

您没有提到您使用的操作系统。
如果您使用的是 Windows,它可能位于 C:\mingwC:\Program Files\mingw .

如果你还没有安装 g++,你可以通过 https://sourceforge.net/projects/mingw-w64/ 安装它

然后打开System Properties -> Advanced -> Environment Variables .

然后下Environment Variables for <username>选择 PATH并点击编辑。

单击“新建”,然后单击“浏览”并找到 bin在您的 mingw 安装目录中,并将其添加到路径中,您就完成了。

如果打开了 VSCode,则重新启动它,它会自动找到 g++。

关于c++ - 'g++' 不是内部或外部命令,也不是可运行的程序或批处理文件。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53975157/

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