How can I use gcc by installing Cygwin on a Windows machine?
Solution 1
I see from your latest comment that it works when you run gcc
from the Cygwin bash shell.
The Access is denied
message was appearing when you tried to run gcc
from the Windows cmd prompt. I don't know why you'd get that particular message.
My advice is just to use the bash shell. (It also has a lot of nice features that the Windows command shell lacks.) If that's a good solution for you, feel free to stop reading now.
But if you really want to use Cygwin tools (such as gcc) from a Windows prompt, you need to update your Windows %PATH%
to include the Cygwin bin directory. As seen from bash, the directory is /usr/bin/
; from Windows, it's going to be something like C:\cygwin\bin
(assuming you installed Cygwin in C:\cygwin
, which is the default).
To permanently add C:\cygwin\bin
to your Windows %PATH%
, open System Properties
in the Control Panel, tap the "Environment variables" button, and adjust the value of Path
in "System variables". Once you've done that, newly opened cmd windows should have the new %PATH%
setting. (The user interface for modifying environment variables isn't exactly use-friendly; maybe somebody else can suggest a better way.)
EDIT:
The cygwin.bat
batch file changes the current director to C:\cygwin\bin
and then launches the Cywgwin bash shell in a new window. That gives you an environment in which gcc
works by default, since your $PATH
is already set up correctly. The windows command shell and the Cygwin bash shell are quite different environments.
Solution 2
If you installed the gcc package for cygwin, you should be able to do simply gcc filename.c
.
The setup.exe
file of Cygwin lets you choose any additional package you want to add when installing. If you skipped it, simply rerun the setup.exe
.
Packages can be also found on the Cygwin website.
Solution 3
does your cmd recognizes gcc as an installed application? if so, try this
gcc -c filename.c -o filename.o
Jeegar Patel
Written first piece of code at Age 14 in HTML & pascal Written first piece of code in c programming language at Age 18 in 2007 Professional Embedded Software engineer (Multimedia) since 2011 Worked in Gstreamer, Yocto, OpenMAX OMX-IL, H264, H265 video codec internal, ALSA framework, MKV container format internals, FFMPEG, Linux device driver development, Android porting, Android native app development (JNI interface) Linux application layer programming, Firmware development on various RTOS system like(TI's SYS/BIOS, Qualcomm Hexagon DSP, Custom RTOS on custom microprocessors)
Updated on June 05, 2022Comments
-
Jeegar Patel about 2 years
i have installed the
cygwin
package for my netbeans IDE. I can use that in netBeans project. But now I want to use the gcc compiler from a cmd prompt. How can I do that?In Linux we open a terminal and type
gcc filename.c
and it compiles. Now I want to do the same thing in Windows with Cygwin's gcc. Can I type
gcc filename.c
in cmd and it compiles? If so, how?Edit :
by writing in cmd
gcc --version
I get
Access is denied
Edit 1: In the C: drive I have a folder named
Cygwin
that containsCygwin.bat
.When I run that, a new prompt is opened and inside that when I type
gcc filename.c
, it works.In that
.bat
file :@echo off C: chdir C:\cygwin\bin bash --login -i
I don't understand what that means.