Eclipse g++ not found in path: windows - c++

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:
Program "g++" not found in PATH
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++:
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:
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
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++".

Related

Function to_string() was not resolved using g++ mingw--w64 5.3.0

In Eclipse I am using mingw-w64 V5.3.0 as the compiler and I have enabled C++11 (which was the solution in the following related post here and here). My compilation command looks as follows (from eclipse console window):
g++ -std=c++11 -O0 -g3 -Wall -c -fmessage-length=0 -o "src\Launch.o" "..\src\Launch.cpp"
The simple code I am attempting to run is as follows:
#include <stdio.h>
#include <iostream>
#include <string>
int main()
{
std::string test = std::to_string(0);
std::cout <<"HI" << std::endl;
return 0;
}
The program compiles but for an error stated in the question. Running it without the to_string line works fine. There have been suggestions back in 2012 that MingW has a problem with to_string(), but was resolved in later versions has shown here.
Screen shot below:
And the console output is as follows:
The following is the error I receive when running the code from the .exe directly:
As mentioned in the comments, the issue is a linking issue, however it is linking correctly to iostream which is in the same directory as string.
Eclipse was looking in System32 for the library and driver files, despite PATH and Eclipse pointing to the MingW64 compiler on the computer. Eclipse is also showing it is linked to the MingW64 libraries correctly as the path to the headers when right-clicking and opening deceleration is shown to be correct. Why then it looks in System32 for the library at run-time I don't understand.
The problem was 'solved' by copying the entire MingW64 compiler driver folder into the System32 folder on Windows.

png++ invalid template arguments Eclipse editor Cygwin symbolic link

I am trying to use Eclipse CDT with the Cygwin GCC toolchain in order to read in some images using png++. I have installed the png++ headers (I tried both 0.2.5 and 0.2.7) in my Cygwin, and it compiles fine using the external builder settings with make, but for some reason the editor underlines "image" from png::image in the very simple code:
#include <png++/png.hpp>
int main( int argc, char* argv[]){
png::image<png::gray_pixel> t(128,128);
return 1;
}
And gives the error:
Invalid template arguments.
I looked around a bit for this error, and it seems for other people it was caused by not having GCC set to use C++11 (such as Invalid template arguments on map std::map< std::string, Stock*> &stocks), but I do not think that is an issue with me, since I have my "CDT GCC Built-in Compiler Settings Cygwin" provider command set to:
${COMMAND} ${FLAGS} -E -P -v -dD -std=c++11 "${INPUTS}"
And the line std::normal_distribution<double> distribution(5.0,2.0); does not give an error.
I can remove the error underline by turning off "Invalid template argument" under the project properties -> C/C++ General -> Code Analysis, but the problem is deeper than that, as none of the auto-completes will work for the object of type png::image, and if I try and use it in a function, for example:
void pngTest(png::image<png::gray_pixel> im, int other) {}
it gives the error: Invalid arguments ' Candidates are: void pngTest(?, int) '
So it seems it does not resolve the type at all. What might be causing this?
Turns out this was not actually a bug with Eclipse parsing, but an incompatibility with Cygwin style symlinks. In png++'s png.hpp and types.hpp it includes png.h from libpng, but in Cygwin png.h (in /usr/include) is a Cygwin style symlink to the current libpng (in my case the file contained the text: !<symlink>libpng16/png.h).
So Eclipse could not resolve this include, even though Cygwin's GCC could, and it was making the typedefs in types.hpp not resolve correctly. This is why I was getting an invalid template arguments error in eclipse, png::gray_pixel was not a valid type. I noticed this when I put <int> instead and it no longer gave an error. So that was the problem.
I changed the include paths from png.h to libpng16/png.h in both png.hpp and types.hpp
and now everything in eclipse is resolving correctly after a right click on the project -> index -> rebuild. Alternatively you could symlink png.h, pngconf.h, and pnglibconf.h in /usr/include to the appropriate libpng subfolder using the windows mklink command and remove the Cygwin style symlinks.
If anyone knows a way for Eclipse to work seamlessly with Cygwin symlinks then post here and I will accept that as the answer, since obviously that is a little better than this hacky fix.
Thank you guys for the comments, but it seems thankfully that this time it was not an Eclipse issue.

Eclipse: Compiles, but CODAN (internal code analyzer) gives errors for functions from C++ 11 <includes>

I have the following code in eclipse:
I'm running Indigo SR 2, 64bit with CDT Version: 8.0.2.201202111925 Build id: #build#
I have the Java SDK, Android SDK, and C++ CDT.
I Believe the problem is only happening with c++ 11 functions: it seems Eclipse's internal code analyzer CODAN is not properly finding the libraries, even though the compiler is (i have the std=C++11 flag on my compilers).
I think this topic is related: http://www.eclipse.org/forums/index.php/t/490066/
#include <iostream>
#include <array>
using namespace std;
int main(){
cout << "test";
array<int,5> myints;
int x = 0;
cout << "size of myints: " << myints.size() << std::endl;
cout << "sizeof(myints): " << sizeof(myints) << std::endl;
return 0;
}
and I'm getting an error/ not compiling because I'm told:
Symbol 'array' could not be resolved
Why am I not compiling? I'm using eclipse indigo with the CDT and cygwin. I can provide more info as necessary.
UPDATE: I compile through eclipse (hammer button or right click project and click build) using Cygwin GCC and the Cygwin PE Parser.
Update 2: Running in indigo gives both an error in editor and a fail to compile, Kepler gives me the error, but seems to succeed running and compiling. Is there a way to make the error go away in kepler? Also, how would I get the actual command being passed to the compiler from within eclipse?
Update 3: More weirdness, after compiling in Kepler, it now compiles in indigo as well, though the errors persist in the text editor in both version.
1) Is there a way I can make these errors more accurate to the compile?
2) I can press f3 on the include and view it's source, so why can't eclipse seem to find the array symbol?
3) I'm also being told that the first std::endl is an Invalid overload of 'std::endl'
Update 4: I tried std::tr1::array<int, 3> arr1 = {1, 2, 3}; and it's still telling me that array cannot be resolved. I've added -std=c++11 to my c/C++ Build -> Settings -> Cygwin C++ Compiler -> Miscellaneous -> Other flags. It now reads: -c -fmessage-length=0 -std=c++11 But I'm seeing no change at this point
Update: This question seems to be getting at the problem:
Eclipse C/C++ Shows Errors but Compiles?
However, I've added a link to the directory "D:/Wamp/cygwin64/lib/gcc/x86_64-pc-cygwin/4.8.2/include" and it hasn't changed anything...
Thanks!
I think I got this resolved by changing the following settings:
Project->Properties->C/C++ General/Preprocessor Include Paths, Macros Etc. -> Providers (tab)
Then "CDT GCC Built-in Compiler Settings" -> click the link "Workspace Settings"
"CDT GCC Built-in Compiler Settings" (again), under "Command to get compiler specs:"
add: "-std=c++11"
It took a refresh and then the little red squiggles went away.
This was the source:
http://www.eclipse.org/forums/index.php/mv/msg/373462/909018/#msg_909018
I also tried following this:
http://scrupulousabstractions.tumblr.com/post/36441490955/eclipse-mingw-builds
but it didn't exactly work. Probably because I'm on Ubuntu.
I had added "-std=c++11" to the end of the "Command to get compiler specs" within Workspace Settings > C/C++ > Build > Settings > Discovery (tab) > CDT GCC Built-in Compiler Settings"...
And I had set my project so "Enable project specific settings" was disabled, under Properties > C/C++ General.
But still I got C++11 related CODAN errors.
I just discovered that unchecking "Enable project specific settings" does not guarantee the project will use the Discovery settings from the workspace. You still have to go in your project to Properties > C/C++ General > Preprocessor Include Paths, Macros etc. > Providers (tab) > CDT GCC Built-in Compiler Settings ... and make sure the option "Use global provider shared between projects" is checked (which it is not by default on my system, running Eclipse IDE for C/C++ version 2019-09 R). With this option checked "CDT GCC Built-in Compiler Settings" now shows [ Shared ] next to it.
There are a few other discovery providers where you need to set a similar option to ensure [ Shared ] shows up in the list (if you are trying to have your workspace settings apply). The "CDT User Settings Entries" I leave as project-specific, but the others I share in order to use the workspace-level settings.
CODAN is now working properly, and I no longer need to manually "freshen" the indexes and/or add #include statements to nudge CODAN along.
C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Dialect -> Language standart -> select which one you want to use.
You don't need to add "-std=c++11" anywhere else

I am getting 5 errors in my "hello world" C++ program

My code is...
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
}
The errors i am getting are...
Description Resource Path Location Type
Symbol 'std' could not be resolved main.cpp /First/src line 3 Semantic Error
Program "g++" not found in PATH First [Discovery Options] page in project properties C/C++ Problem
Program "gcc" not found in PATH First [Discovery Options] page in project properties C/C++ Problem
Symbol 'cout' could not be resolved main.cpp /First/src line 8 Semantic Error
Program "make" not found in PATH First C/C++ Problem
Does anybody know whats wrong? This is my first time trying C++ and i am using eclipse-cpp-kepler-SR1-win32-x86_64
I can't comment yet but based on the error messages it seems that the compiler has not been setup properly or Eclipse cannot find it.
http://www.eclipse.org/forums/index.php/t/238347/
Make sure Eclipse can find your compiler.
You may have to setup some environment variables.
http://www.computerhope.com/issues/ch000549.htm
Also try following the instruction in the error message.
I hope that helps.
install g++ in your system and set env path!
In my case on osx, the errors on the basic hello world project were caused by something silly. everything was installed but i had no clue that the gcc expected me to read and agree to a License. go to terminal and type $ gcc. i was then prompted with the need to deal with the license agreement. once that was done, eclipse build the hello world project without problem. hope this helps others ...

Setting up MingW and Code::Blocks in Windows 8 64 bit

I am trying to setup MingW and Code::Blocks on my Windows 8 64 bit laptop, and I'm facing some problem while building a main.cpp file. These are the versions that I have installed:
x86_64-w64-mingw32-gcc-4.7.4-release-win64_rubenvb.7z for MingW (4th one in that list), and
codeblocks-12.11-setup.exe for Code::Blocks.
I've set the path to mingw64\bin in the environment variable. Also, in the Code::Blocks compiler settings, I have set path for all ToolChain Executables. There are two gcc in the MingW bin path. One is - gcc.exe and other is - x86_64-w64-mingw32-gcc.exe. Same for C++ Compiler, Linker for static and dynamic libs. Now when I try to build a simple Hello World file, it shows some errors:
obj\Debug\main.o -- In function swscanf
c:\mingw\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\4.7.3\..\..\..\..\x86_64-w64-mingw32\include\wchar.h -- undefined reference to `__gxx_personality_sj0'
obj\Debug\main.o -- In function `wscanf':
c:\mingw\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\4.7.3\..\..\..\..\x86_64-w64-mingw32\include\wchar.h -- undefined reference to `__gxx_personality_sj0'
Similarly there are many errors and undefined references for - fwprintf, wprintf, std:cout, etc..
I'm sure there is some configuration problem, but I cannot find out what's the issue. Can any one take a look at the problem.
Here's the code I'm running:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
If you don't require 64 bit support, consider downloading "codeblocks-12.11mingw-setup.exe"
It packs its own 32 bit mingw and has everything preconfigured for you.
Otherwise, if you still need to compile amd64 apps:-
Assuming you extracted to D:\Mingw64, under the "Tool Chain Executables" tab, set the "Compiler's Installation Directory" to "D:\Mingw64\bin", Then click auto-detect to check whether code::blocks likes what it finds.
If everythings Ok, make sure the rest of the fields are as follows:-
C compiler: x86_64-w64-mingw32-gcc.exe
C++ compiler: x86_64-w64-mingw32-g++.exe
Linker for dynamic libs: x86_64-w64-mingw32-g++.exe
Linker for static libs: x86_64-w64-mingw32-ar.exe
Debugger: GDB/CDB Debugger...
Ressource compiler: x86_64-w64-mingw32-windres.exe
Make program: mingw32-make.exe
Click on the "Additional Paths" tab and enter the following line:- (the path is correct for ver 4.7.4,the one you downloaded. It ends with 4.7.3)
D:\Mingw64\libexec\gcc\x86_64-w64-mingw32\4.7.3\
Click on the "Search directories" tab to the imediate left "Toolchain Executables"
Add the following paths:-
D:\Mingw64\include
D:\Mingw64\x86_64-w64-mingw32\include
D:\Mingw64\x86_64-w64-mingw32\include\c++\4.7.3
D:\Mingw64\x86_64-w64-mingw32\include\c++\4.7.3\backward
D:\Mingw64\x86_64-w64-mingw32\include\c++\4.7.3\x86_64-w64-mingw32
D:\Mingw64\lib\gcc\x86_64-w64-mingw32\4.7.3\include
Click on the "linker" tab and add the following paths:-
D:\Mingw64\Lib
D:\Mingw64\x86_64-w64-mingw32\lib
And finally click on the "Compiler Settings tab", Click on "Other options" and add:-
-m64
One last thing-> remember to save those settings to disk!
If it crashes while you test this new config, you might wish you had!
Do this (I think) either by "File->Save Everything" or restarting code::blocks ...without another instance running.
Try compiling something then share the outcome
Peace! Dear brother, I think you need this:
(1)
std::cout << "Hello world!" << std::endl;
You need to put "std::function_name" whenever you are using a predefined function from iostream.h, because this is you way access it in GCC, which Code::Blocks uses.
(2) Try it compiling by omitting "using namespace std;" from your code.
Because I've compiled C and C++ code many times in Code::Blocks on 32-bit Windows XP, and it did!
(3) Make sure the path is set to the directory "mingw\bin".
(4) Ensure if you have 64-bit MinGW installed and path set to its "bin" directory (if you want to compile for 64-bit). It will compile for 64-bit by default.
(5) Try the flags/arguments "-m32" and "-m64" for compiling for 32- and 64-big respectively.