简体   繁体   中英

Eclipse g++ not found in path: windows

I am attempting to setup SDL2 for C++ with Eclipse on Windows 7.

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 link provided 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:

#include <iostream>

using namespace std;

int main() {
    cout << "Hello World!" << endl;
    return 0;
}

To my surprise, this code doesn't build, with 6 errors.

I then proceed to simplify the program further:

int main()
{
    return 0;
}

This also does not compile. There are two errors:

  1. Program "g++" not found in PATH
  2. Program "gcc" not found in PATH

Here is a screenshot. 构建错误

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++: 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".

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:

  1. Eclipse mingw binary not found
  2. Eclipse not finding c std libraries
  3. g++ not found in path
  4. Eclipse C++ : "Program g++ not found in PATH"
  5. Program g++ not found in path
  6. Program g++ not found in path C++ [duplicate]
  7. Eclipse CDT (Juno) in Win7: Cannot find g++ in PATH, iostream unresolved and other fun stuff

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 .

I have also reinstalled Eclipse to no avail.

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.

You need to set the environment for the c/c++ builder.

  • 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->Environment and 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:

在此输入图像描述

  • Now when you create a new project you just have to select the MinGW tool-chain:

在此输入图像描述

Hope that helps.

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++".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM