Search code examples
eclipseeclipse-cdt

Suppress "program not found" errors in Eclipse CDT


Most of my team uses a .bat file to set paths and then run a build. The .bat file allows selection of multiple different compiler/target platforms, but all use some version of GCC/G++ or similar compiler.

I created an Eclipse project that simply uses the .bat file rather than re-inventing the wheel and tracking down all the paths needed for each build (which I'd need to update if anyone ever updated the .bat file anyway).

This works great for building, and I can even see compiler errors/warnings, but there are some extra errors always present:

Program "gcc" not found in PATH
Program "g++" not found in PATH

I've seen many questions about these and similar errors, but in those case the user couldn't build, and the solution was to install the tools and/or update their PATH or Eclipse environment settings. I don't want to do that; all the tools I need are installed, and the .bat file works just fine to set the PATH for building. Is there a way to suppress these errors, or have Eclipse not try to find the compiler executable, since the build succeeds anyway?


Edit: As suggested in the answer I've received so far, here is output on the console after putting a full path to a compiler in the global discovery settings, which isn't exactly my favorite solution even if it worked, but I'll probably deal with it. Regardless the errors don't go away:

15:27:24 **** Running scanner discovery: CDT GCC Built-in Compiler Settings MinGW ****
"C:\\redacted\\localapps\\MinGW5\\bin\\g++.exe" -E -P -v -dD C:/Project_Files/redacted/code_workspaces/redacted/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C 
Reading specs from C:/redacted/localapps/MinGW5/bin/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)
 C:/redacted/localapps/MinGW5/bin/../libexec/gcc/mingw32/3.4.2/cc1plus.exe -E -quiet -v -P -iprefix C:\redacted\localapps\MinGW5\bin\../lib/gcc/mingw32/3.4.2/ C:/Project_Files/redacted/code_workspaces/redacted/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C -dD
ignoring nonexistent directory "C:/redacted/localapps/MinGW5/bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include"
#define __cplusplus 1
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/../../../include/c++/3.4.2"
#define __STDC_HOSTED__ 1
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/../../../include/c++/3.4.2/mingw32"
#define __GNUC__ 3
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/../../../include/c++/3.4.2/backward"
...

And then a bunch of #defines

The command string I used in the discovery options for this output was C:\redacted\localapps\MinGW5\bin\${COMMAND}.exe ${FLAGS} -E -P -v -dD "${INPUTS}".


Solution

  • Based on the information provided, these errors are coming from the scanner discovery part of CDT.

    On my machine the full error looks like this:

    Description                             Location                                                                                        Type
    Program "g++" not found in PATH         Preferences, C++/Build/Settings/Discovery, [CDT GCC Built-in Compiler Settings MinGW] options   C/C++ Scanner Discovery Problem
    Program "gcc" not found in PATH         Preferences, C++/Build/Settings/Discovery, [CDT GCC Built-in Compiler Settings MinGW] options   C/C++ Scanner Discovery Problem
    

    Or as a screenshot

    problems view

    What is going on here is Eclipse CDT is (attempting to) launch GCC and G++ to find out what the global settings are for things like include paths, etc.

    To fix the problem, go to the Location specified in the error message and adjust the scanner settings. Here is the matching setting to go with the specific error I received.

    enter image description here

    Your error might be in the project or in the global settings.

    To update the MinGW setting, you can provide the path to a batch file that looks like GCC/G++ but sets up your environment correctly first, or you can point directly at the GCC that Eclipse CDT did not find on its own.

    For example you can have:

    D:\path\to\my\compilers\${COMMAND}.exe ${FLAGS} -E -P -v -dD "${INPUTS}"
    

    As the setting instead of the default.

    To aid the debugging, check the Allocate console in the Console View to see exactly what is being run and what output is being generated.

    And here is what you might see when it does not work. Hopefully the error messages in the console are sufficient to resolve the problem on your machine.

    21:12:54 **** Running scanner discovery: CDT GCC Built-in Compiler Settings MinGW ****
    "D:\\path\\to\\my\\compilers\\g++.exe" -E -P -v -dD C:/Temp/workspace/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C 
    Cannot run program "D:\path\to\my\compilers\g++.exe": Launching failed
    
    Error: Program "D:\path\to\my\compilers\g++.exe" not found in PATH
    PATH=[\bin;\bin; -- snip --]
    
    21:12:54 Build Finished (took 37ms)
    

    Here is a screenshot to match:

    enter image description here

    If it does work, you should see lots of #defines and the like showing the global state of your compiler.