Reputation: 27210
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.
Upvotes: 4
Views: 12718
Reputation: 3777
gcc is actually a link (which the Command Prompt does not understand). Use gcc-3 or gcc-4 if you need to use the Command Prompt.
Upvotes: 0
Reputation: 263267
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.
Upvotes: 5
Reputation: 135
does your cmd recognizes gcc as an installed application? if so, try this
gcc -c filename.c -o filename.o
Upvotes: 1
Reputation: 18743
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.
Upvotes: 1