C++ 在路径中找不到 Eclipse g++:windows
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31911815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse g++ not found in path: windows
提问by Matt Martin
I am attempting to setup SDL2 for C++ with Eclipse on Windows 7.
我正在尝试在 Windows 7 上使用 Eclipse 为 C++ 设置 SDL2。
In order to do so, I am following the tutorial in this link, which states that I must first install MinGW. So I follow the linkprovided in order to setup MinGW. I follow all the steps without issue. I then open Eclipse and attempt to build a simple hello world program:
为此,我遵循此链接中的教程,其中指出我必须首先安装 MinGW。所以我按照提供的链接来设置 MinGW。我按照所有步骤没有问题。然后我打开 Eclipse 并尝试构建一个简单的 hello world 程序:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
To my surprise, this code doesn't build, with 6 errors.
令我惊讶的是,这段代码没有构建,有 6 个错误。
I then proceed to simplify the program further:
然后我继续进一步简化程序:
int main()
{
return 0;
}
This also does not compile. There are two errors:
这也不能编译。有两个错误:
- Program "g++" not found in PATH
- Program "gcc" not found in PATH
- 在 PATH 中找不到程序“g++”
- 在 PATH 中找不到程序“gcc”
However, my path does contain "C:\mingw\bin". I have also tried changing this to "C:\mingw". Looking inside "C:\mingw\bin", I find gcc and g++:
但是,我的路径确实包含“C:\mingw\bin”。我也尝试将其更改为“C:\mingw”。查看“C:\mingw\bin”内部,我发现 gcc 和 g++:
In addition, compiling a test program using the command line (g++ Test.cpp -o Test) works just fine, as does "g++ -v".
此外,使用命令行 (g++ Test.cpp -o Test) 编译测试程序工作正常,“g++ -v”也是如此。
I have been searching the web for hours, and can't seem to find an answer as to why Eclipse can't seem to compile anything with MinGW. Questions I have looked at on SO (which haven't been able to fix my issue) include:
我已经在网上搜索了几个小时,似乎无法找到为什么 Eclipse 似乎无法用 MinGW 编译任何东西的答案。我在 SO 上查看的问题(无法解决我的问题)包括:
- Eclipse mingw binary not found
- Eclipse not finding c std libraries
- g++ not found in path
- Eclipse C++ : "Program g++ not found in PATH"
- Program g++ not found in path
- Program g++ not found in path C++ [duplicate]
- Eclipse CDT (Juno) in Win7: Cannot find g++ in PATH, iostream unresolved and other fun stuff
- 找不到 Eclipse mingw 二进制文件
- Eclipse 找不到 c std 库
- 在路径中找不到 g++
- Eclipse C++:“在路径中找不到程序 g++”
- 在路径中找不到程序 g++
- 在路径 C++ 中找不到程序 g++ [重复]
- Win7 中的 Eclipse CDT (Juno):在 PATH 中找不到 g++、iostream 未解析和其他有趣的东西
Additional info:Window > Preferences > C/C++ > Build > Settings > "CDT GCC Built-in Complier Settings MinGW [Shared]" : Toolchain MinGW GCC is not detected on this system.
附加信息:窗口 > 首选项 > C/C++ > 构建 > 设置 > “CDT GCC 内置编译器设置 MinGW [共享]”:在此系统上未检测到工具链 MinGW GCC。
I have also reinstalled Eclipse to no avail.
我也重新安装了 Eclipse 无济于事。
I realize that this may be a duplicate question of some that I have linked, but the information in previous questions have not been able to fix my problem, and I fear that adding a comment to an old question may not result in an answer.
我意识到这可能是我链接的某些问题的重复问题,但之前问题中的信息无法解决我的问题,我担心向旧问题添加评论可能不会得到答案。
Please request additional information as needed.
请根据需要索取其他信息。
回答by Jhossep Augusto Popayán Avila
You need to set the environment for the c/c++ builder.
您需要为 c/c++ 构建器设置环境。
- First you need to install the GNU tool-chain, you can choose either MinGW or Cygwin. You can see the steps here. I used MinGW.
- Go to Window->Preferences->C/C++->Build->Environmentand add a new variable, name it whatever you want for example a named it "MINGW", now paste the binaries directory of MinGW which is by default C:\MinGW\bin, you should have something like this:
- 首先您需要安装 GNU 工具链,您可以选择 MinGW 或 Cygwin。您可以在此处查看步骤。我使用了 MinGW。
- 转到Window->Preferences->C/C++->Build->Environment并添加一个新变量,将其命名为您想要的任何名称,例如将其命名为“MINGW”,现在粘贴 MinGW 的二进制目录,默认情况下为C: \MinGW\bin,你应该有这样的东西:
- Now when you create a new project you just have to select the MinGW tool-chain:
- 现在,当您创建一个新项目时,您只需选择 MinGW 工具链:
Hope that helps.
希望有帮助。
回答by Matt Martin
It appears as though I have fixed the problem for the moment.
看来我暂时已经解决了这个问题。
In case others encounter the same issue: Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Command changed from "g++" to "C:\mingw\bin\g++".
如果其他人遇到同样的问题:项目 > 属性 > C/C++ 构建 > 设置 > MinGW C++ 链接器 > 命令从“g++”更改为“C:\mingw\bin\g++”。