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 contains Cygwin.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.
I see from your latest comment that it works when you run
gccfrom the Cygwin bash shell.The
Access is deniedmessage was appearing when you tried to rungccfrom 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 likeC:\cygwin\bin(assuming you installed Cygwin inC:\cygwin, which is the default).To permanently add
C:\cygwin\binto your Windows%PATH%, openSystem Propertiesin the Control Panel, tap the “Environment variables” button, and adjust the value ofPathin “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.batbatch file changes the current director toC:\cygwin\binand then launches the Cywgwin bash shell in a new window. That gives you an environment in whichgccworks by default, since your$PATHis already set up correctly. The windows command shell and the Cygwin bash shell are quite different environments.