What command does one have to enter at the command line in Windows 7 to compile a basic C program?
Like I am literally wondering what you type in the command prompt, to
I had the same problem with .c files that contained functions (not main()
of my program). For example, my header files were "fact.h" and "fact.c", and my main program was "main.c" so my commands were like this:
E:\proj> gcc -c fact.c
Now I had an object file of fact.c (fact.o). after that:
E:\proj>gcc -o prog.exe fact.o main.c
Then my program (prog.exe) was ready to use and worked properly. I think that -c
after gcc
was important, because it makes object files that can attach to make the program we need. Without using -c
, gcc ties to find main in your program and when it doesn't find it, it gives you this error.
Just set the environment variable to the EXACT path to gcc.exe like this:
C:\Program Files (x86)\CodeBlocks\MinGW\bin\gcc.exe
If you pasted your text into the path variable and added a whitespace before the semicolon, you should delete that and add a backslash at the end of the directory (;C:\Program Files (x86)\CodeBlocks\MinGW\bin
I am quite late answering this question (5 years to be exact) but I hope this helps someone.
I suspect that this error is because of the environment variables instead of GCC. When you set a new environment variable you need to open a new Command Prompt! This is the issue 90% of the time (when I first downloaded GCC I was stuck with this for 3 hours!) If this isn't the case, you probably haven't set the environment variables properly or you are in a folder with spaces in the name.
Once you have GCC working, it can be a hassle to compile and delete every time. If you don't want to install a full ide and already have python installed, try this github project: https://github.com/sophiadm/notepad-is-effort It is a small IDE written with tkinter in python. You can just copy the source code and save it as a .py file
I've had this problem and couldn't find why it kept happening. The reason is simple: Once you have set up the environment paths, you have to close the CMD window, and open it again for it be aware of new environment paths.
I encountered the same error message after unpacking MinGW archives to C:\MinGW
and setting the path to environment variable as C:\MinGW\bin;
.
When I try to compile I get this error!
gcc: error: CreateProcess: No such file or directory
I finally figured out that some of the downloaded archives were reported broken while unpaking them to C:\MinGW
(yet I ignored this initially).
Once I deleted the broken files and re-downloaded the whole archives again from SourceForge, unpacked them to C:\MinGW successfully the error was gone, and the compiler worked fine and output my desired hello.exe
.
I ran this:
gcc hello.c -o hello
The result result was this (a blinking underscore):
_