9

I have installed Cygwin on my system. But when I try to use the gcc command it says:

bash: gcc: command not found

Can anyone provide me the solution, please?

0

5 Answers 5

17

In my installation there was no generic gcc command either, so I made a symlink for it:

cd /usr/bin
ln -s i686-pc-cygwin-gcc-3.4.4.exe gcc

Now check if it worked by doing which gcc which should give you /usr/bin/gcc and then gcc should give you gcc: no input files. Note that your version of i686-pc-cygwin-gcc-3.4.4.exe may be different. Check in /usr/bin for it.

4

Maybe during installation of Cygwin you have not selected gcc, gdb and make packages.

I had the same problem and it was resolved after I selected above-mentioned packages.

1
  • 1
    The link is dead, If you could bring in the relevant steps if you still have them.
    – Nathan
    Commented Aug 1, 2016 at 16:14
2

A couple of things:

  • I always install the whole Cygwin package. Earlier versions had troubles with dependencies that are fixed now, I believe, but it's still a good habit. You never know when you may need the most esoteric bit of Cygwin.

  • You may have to change your path. All the tools can generally be found okay if you're running inside the Cygwin bash shell but that's not necessarily the case from cmd.exe.

It's unlikely to be that last one since your error message is coming from bash itself, so I'm pretty certain that's how you're running it.

Have a look to make sure you have /usr/bin/gcc from within bash and that your path includes /usr/bin somewhere:

pax> echo $PATH
/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS

pax> which gcc
/usr/bin/gcc

If it's not there, go back and re-install everything (or the relevant development package if you don't want everything). If it is there and your path doesn't have its location, change your path, in either /etc/profile or the equivalent in your home directory.

0

Another related issue that wasn't mentioned here, is from the command line the compiler needs the environment path variable updated to find the location of the c++ header files. In windows you can just update the path environment using the 'advanced system properties' GUI and add the location of the c++ include files. This will update the PATH environment variable in Windows cmd & Cygwin automatically upon restarting the shell.

To update your PATH from Linux or the Cygwin shell type... PATH=$PATH:/your_path_here Example:PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/c++ Also a good idea to add just the include directory as well: PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/ ...or check the proper directories for the location of your installation's include files, I recommend installing mingw for use with Cygwin, which is envoked with g++.

To install additional needed packages in Cygwin re-run the Cygwin install utility & check install from Internet to add packages from web repositories and add mingw-gcc-g++ & mingw-binutils. To compile your code: g++ hello.cpp -o hello

If using the gcc utility instead compile with the command: gcc hello.cpp -o hello -lstdc++ ... to get your executable.

As long as you have either gcc or mingw installed and the path to the c++ include files is in your path environment, the commands will work.

0

There is another hard to spot mistake could also cause this error,

If your Makefile uses PATH as variable, the gcc not found error could happen.
This is because it changes the system path temporarily.

I took a lot of time checking the cygwin environment setting to discover this, so I'll leave it here in case this helps anyone finding their way here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.