g++ not working on Windows command prompt. Cygwin installed - c++

I have installed Eclipse and CDT (to use C/C++ in eclipse CDT is needed), as well as installing Cygwin so that I can compile my files.
In environment variables I've set Path to include the following: "C:\cygwin\bin;"
g++, make and GDC are all installed via Cygwin. I made sure of this by searching for them in the bin folder - they're all there.
If I enter "make" into the windows command prompt, this appears:
make: *** No targets specified and no makefile found. Stop.
If I enter "g++" or "gdc" into the windows command prompt, this appears (or similar):
'g++' is not recognized as an internal or external command,
operable program or batch file.
So, in other words make is working but the rest isn't..but they're in the same bin folder! Has got me completely confused.
If I attempt to open Cygwin Bash Shell, g++, make and GDC all work there.
However, I need it to work in the command prompt so that Eclipse is able to compile the programs I write in the IDE.
If you know why this is happening, please let me know.

I haven't used cygwin much, but my understanding is you have to use it from the cygwin bash shell.
if you need g++, make, etc, use mingw, with it, g++ works from the normal windows command line.

Here is what happened to me and how I fixed it.
My C:\cygwin\bin\g++.exe is a shortcut pointing to C:\etc\alternatives\g++.exe, which points back to C:\cygwin\bin\g++-3.exe.
Replacing g++ with g++-3 worked for me.

In C:\cygwin\bin see whether g++.exe is there. If not, the installation wasn't done properly and you may need to install again. That's what was my problem and it's resolved :)

Adding the cygwin paths to the Path variable worked for me (windows 8.1 64 bit):
Go to system properties and select advanced system properties
Go to environment variables and select Path in system variables, click edit
Add the Cygwin paths...
for 32 bit:
C:\Cygwin\bin;C:\Cygwin\usr\bin
for 64 bit:
C:\Cygwin64\bin;C:\Cygwin64\usr\bin

In the CMD window, try typing bash to start a bash shell in that window. If that doesn't work, then the cygwin bin directory is not on your path.
If it did work, enter type g++ and type make to see the paths that are being used for these commands. I'm pretty sure your problem is with your PATH variable.

You could install a Windows version of which to get some help in figuring out exactly which executables are being run.
Perhaps it's picking up 'make' from somewhere completely different, and your addition to %PATH% is not working.
Also verify it by typing echo %path% in the same command prompt window as you're seeing the problem in, just to make sure.

Related

Eclipse with CDT on Mac

I've been trying to get Eclipse with CDT working on my Mac for a while now. Everything I've searched for talks about Windows and I'm officially stuck.
The errors I get are:
Program "g++" not found in PATH
Program "gcc" not found in PATH
and a few more that seem to stem from a problem with my PATH. I checked gcc, g++, make, and gmake in terminal using --version and they're all installed. Eclipse CDT is supposed to detect where to look for PATH variables and I can't figure out where I would change it or how to change it. Any help would be greatly appreciated!
Edit: The original problem was fixed. My PATH variable in eclipse was empty for some reason so I had to add locations like /usr/bin and /usr/local/bin. Now I get the error that "Symbol 'cout' could not be resolved."
Edit 2: I was able to get everything working by uninstalling everything and reinstalling Eclipse Indigo with CDT.
There is no C / C++ compiler installed.
Options are:
Install gcc from here (best): https://github.com/kennethreitz/osx-gcc-installer
Install all of Xcode (1 gig install)
Install command line tools only from Xcode https://developer.apple.com/downloads/index.action
Once installed make sure you can call the compiler from the command line (type gcc) if it does not work the compiler has not been added to the environment path variable.
Some extra help:
How do I install g++ on MacOS X?
Here is a great tutorial that shows all the necessary steps for linux. I think it should be quite similar.
http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/
Maybe you'll have to add the path to gcc to your PATH variable if none of this is helping. It should work like this:
Open up .bash_profile in a text editor. (If you're using TextEdit, you can do this at the command line with "open -a /Applications/TextEdit.app ~/.bash_profile".) Add the line:
export PATH="/usr/local/bin:$PATH"
to the file. Save the file and open up a new terminal, then type "echo $PATH" to see if it worked correctly.
EDIT: Someone else had the exact same output as you and managed to fix it by replacing his Eclipse version with an older one. You may try to use Helios instead of Indigo or Juno. This is just a temporary solution until something better comes up (in case it really works). I actually prefer Indigo and Helios over Juno, to be honest. In case you have any worries - Helios is the release from 2010 and still pretty good.
For cout - do you have #include ? Note that cout is a part of std namespace - you need to either qualify it or use "using" directive.
You have to alter ~/.bash_profile, see below for the procedure:
open terminal window
send cmd echo $PATH, then copy the -bash output
send cmd touch ~/.bash_profile
send cmd open -a TextEdit.app ~/.bash_profile
bash_profile will be opened, an empty text file, it means, it the first time it is created.
write in the empty bash_profile: PATH='paste the copied items from echo $PATH cmd a while a back'
save it and reopen the terminal, verify the echo $PATH again.
Restart your eclipse.
my solution is
in preference-> c/c++ -> build->enviroment add PATH= /usr/local/bin
hope it is fine for you.

Netbeans and MinGW-w64

I'm trying to configure my NetBeans on win7 64bit, to work with the MinGW-w64.
So I put in the %PATH% variable the following paths of the compiler:
C:\mingw-w64-bin_i686\mingw\bin
C:\minGw-MSYS\msys\bin
C:\mingw-w64-bin_i686\libexec\gcc\x86_64-w64-mingw32\4.7.0
Then I opened NetBeans and this was configured:
The configuration in NetBeans
I tried to compile a little test program but I received this error:
g++.exe: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not
found compilation terminated. make[2]: *
[dist/Debug/MinGW-Windows/test.exe] Error 1 make1: [.build-conf]
Error 2 make: ** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
I do have this file in C:\mingw-w64-bin_i686\libexec\gcc\x86_64-w64-mingw32\4.7.0
what am I missing?
Right, after months of putting this off I've finally sat down and done it. I'll probably make a more detailed post on my blog with pretty pictures but here is a trimmed down SO version which will hopefully be enough for you (and everyone else) to get going with.
Prerequisites
Remove MinGW, MSYS and CMake if you have them and can afford to lose them (we will reinstall MinGW (obv.) and MSYS but not CMake as it doesn't appear to be needed.)
Netbeans or other suitable IDE
64bit Windows.
EnvMan (optional but handy for managing Windows Environment
variables.)
Installation
MinGW-W64 C compiler and MSYS
Download and install MinGW-W64
http://mingw-w64.sourceforge.net/ (link is on the left menu with a
hyperlink called 'WIN64 Downloads'.)
There are a lot of versions which can be a bit complicated. We are
going with mingw-w64-bin_i686-mingw_20111220 (although the numbers at
the end may be different) which basically says we want the version
with the windows binaries.
Once the download is complete (about 300mb so 10min or so) extract to
C:\MinGW-W64 or similar. Make sure there aren't any spaces in the
path!
Download MSYS for MinGW-W64
Took a bit of searching
http://sourceforge.net/apps/trac/mingw-w64/wiki/MSYS is the wiki for
it and
http://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/MSYS%20%2832-bit%29/
is where I found the download and the version I went with was
MSYS-20111123
Once the download is complete extract the files to C:\MSys or
similar. Make sure there aren't any spaces in the path!
Setup
Add 'C:\MinGW-W64\bin' to your Windows PATH variable.
Add 'C:\MSys\msys\bin' to your Windows PATH variable.
Start Netbeans and go to Tools -> Options -> C/C++.
Click 'Add' under 'Tool Collection' and select the base directory of
MinGW-W64 (C:\MinGW-W64\bin).
Select 'MinGW' from 'Tool Collection Family' if it isn't
auto-detected and click 'OK'.
Set the 'C Compiler to C:\MinGW-W64\bin\x86_64-w64-mingw32-gcc.exe.
Set the 'C++ Compiler to C:\MinGW-W64\bin\x86_64-w64-mingw32-g++.exe.
Set the 'Make Command' to C:\MSys\msys\bin\make.exe.
And that should be it!
I should note that I am using the system to compile a library file to be use via JNI so have some additional steps for that which I missed out as they weren't needed here. However I made a quick 'Hello World' program and it compiled and ran nicely.
Happy coding!
I have just downloaded the latest automated build, unzipped it, added the main bin directory to path, and run:
x86_64-w64-mingw32-gcc test.cpp -o test.exe
and
x86_64-w64-mingw32-gcc -fuse-linker-plugin test.cpp -o test.exe
and it works. The same for the i686 variant. Your IDE is doing something wrong. Or you shouldn't have messed with the files. Or you shouldn't have removed the prefixes. Seriously.
PS: You only have to add the main "bin" directory to PATH, all the rest is wrong.
With some searching via your favorite Internet search engine, I have come across a better approach to quickly add MinGW-x64 to a Windows 64-bit system. On the Sourceforge site is MSYS2.
While following the installation directions and obtaining the most up to date packages, there may be a time out at the primary mirror site on Sourceforge. If so, follow the mirror site update directions and update the three pacman text files in the respective MSYS2 directory (e.g. /etc/pacman.d). Then proceed to complete the package updates from the MSYS2 installation directions.
Within the MSYS2 packages are things like gcc, llvm, make, dmake, etc. Here is the command used from the MSYS2 command line shell (e.g. bash) to install the GNU make utility:
$ pacman -S msys/make
The executable location it will be placed is: /usr/bin inside the MSYS2 command shell. As far as configuring Netbeans for where make.exe is located, the Windows path is:
MSYS2 installation directory\usr\bin\make.exe
(e.g. C:\msys64\usr\bin\make.exe).
To successfully build C++ with Netbeans, I used the GNU make package (e.g. msys/make). Then in order to use the default make files that Netbeans manages, and to not interfere with other C++ compilers within your Windows installation (e.g. Visual Studio, Intel, CLang from Visual Studio, etc.), run Netbeans from the MinGW-x64 command shell provided by MSYS2. In this way, the environment variables and other things like:
ls rm mkdir
will indicate successful execution and compilation within the Netbeans internal terminal window. I opened the MinGW-w64 Win64 Shell by navigating to the installed shortcut from MSYS2's installation. Then pasted into the MinGW-x64 shell command line, the Target property value from the Netbeans Windows desktop shortcut:
$ "C:\Program Files (x86)\NetBeans 7.4\bin\netbeans.exe"
And then could finally create the respective debug and release object and executable files. I also modified the Netbeans project output to be within the MSYS2 directory structure. Then run the executable within the MSYS2 MinGW-x64 shell. Running from the Netbeans IDE produces this error message:
Unable to start pty process: The application failed with exit code
-1073741515 (0xc0000135).
If the MSYS2 path were in the computer system's PATH environment variable, then perhaps this error would not happen.

Is make no longer included with MinGW and/or MSYS?

I installed MinGW and MSYS on my Windows 7 computer. I added C:\Program Files (x86)\MinGW\bin to my path. Commands such as gcc and g++ work, but make does not. I looked in the directory, and there is no executable called make, even though I installed all components. There is a file called mingw32-make. There are also other files prefixed with mingw32-, such as c++, g++, gcc, gcc-4.6.1, and gfortran. However, there is a make in C:\Program Files (x86)\MinGW\msys\1.0\bin.
If I open the MinGW Shell and type in make, make executes. However, it does not execute from the Windows terminal.
Is this intentional, or could I be missing other executables as well? Should I just add C:\Program Files (x86)\MinGW\msys\1.0\bin to my path?
Yup, add the msys bin directory to your path (after MinGW's bin dir). That's exactly what the MinGW shell does and why it works there.
Try gmake. Sometimes the GNU version of Make installs itself as gmake in order to distinguish from non-GNU Make.
C:\Program files\xxx has spaces in it! Since shell scripts are involved, spaces are significant and have to be escaped. Hence this path will not work with mingw. The documentation recommends to install MingW in C:\MingW.
MSYS Answer
Open up your MSYS command terminal (is installed with latest MSYS).
Type in "make". It will say it doesn't exist.
Accordingly with: https://packages.msys2.org/package/make, type in pacman -S make. Type Y for yes.
Make is now installed!
Type "make", and it ask you to specify input files.
Probably only call it from the MSYS command terminal.
Pin MSYS command terminal to taskbar by right-clicking its taskbar icon while it's running.

Getting mingw-get to install correctly - mingw/msys path missing plus more!

I'm running windows XP.
I have been following this tutorial and so downloading mingw-get-inst here.
I've done this a couple times and the last time I checked boes to install EVERYTHING including, but not limited to, gcc, g++, MSYS and the MinGW Compiling Suite. I told it to make a program menu shortcut, too.
I believe I have correctly added MinGW/bin to the Environment Settings' Path.
So I have the shortcut to the MSYS shell now. It goes to C:\MinGW\msys\1.0\msys.bat, but the whole msys directory does not exist!
There are tons of "packages" have been downloaded as far as I can tell ("mingw-get show" brings up a lot!), but it doesn't seem like any of it installed correctly.
Also, should I be able to use commands like "g++ foo.cpp -o foo.exe" from cmd.exe or only from the MSYS shell? Because I was unable to use cmd.exe.
Please help!
The MSYS and MinGW installation procedure is a nightmare, and has got worse over the years. If you just want the compiler suite (no UNIX tools like sed, grep), then I suggest you go to Twilight Dragon Media and download GCC from there. If you also want all the tools, including the Bash shell, the easiest way I've found to get them is to install Git for Windows (which you may want anyway), which includes them all. And if you want a C++ IDE that works well with GCC, take a look at Code::Blocks.
What is the result of running, at a cmd.exe prompt, the command echo %Path%? It should (given what you wrote about your system) include “C:\MinGW\bin”—does it?
What is the result of running dir C:\MinGW?
Note that mingw-get show shows details of available packages—those mingw-get knows how to download and install. The installer is a bit primitive, but has gotten better over the last year or so.
If you issue the command $ echo $PATH, you'll notice it contains /mingw/bin But the /mingw directory is unavailable. To mount it, edit the MSYS fstab, adding a line like C:\MinGW /mingw For details, see the MingW Getting Started guide, more specifically section "After Installing You Should..."
You only need to add MinGW/bin to the Windows' Environment Settings' Path if you plan to use MingW's executables outside of MSYS.

How to make exe in Qt?

I'm starting to learn Qt and I'm stuck on particular step, which is: I cannot create executable file. My steps are as follows:
Creation of *.cpp
In console typing qmake -project (this creates .pro file)
In console typing qmake -makefile (now I have makefile + some other files)
I'm trying to create .exe by typing qmake but this isn't working. I've also tried nmake, bmake and make but no results.
Any help will be appreciated.
Thank you.
It depends on what compiler you are using. If you're using GCC or MinGW, type make. If make cannot be found, either it is not installed, or it's not in your path (more likely to be the case). Try using the command prompt shortcut Qt provides you (if on Windows). If on a POSIX-based/-like system, make should exist. If it doesn't, then it depends if you're on a Mac or on Linux/BSD. On a Mac, make should come with the developer tools, which is one of the last CDs in the OS X installation CDs. If you're on Linux, use your package manager. rpm for Red Hat based systems, apt for Debian based systems, and so on. Google about them.
If you're using Visual C++ and nmake doesn't work, it could mean that nmake isn't on your path. Try using the Visual C++ command prompt instead of the normal command prompt (should be somewhere in your start menu).
It would be more helpful if you could mention how you installed Qt, and on what system.
I believe you need to do something like:
qmake -o Makefile hello.pro
Then type make or nmake depending on the compiler you use.