When i type the command gcc filename.c
a new file 'a.exe' is created, then i have to run a.exe
to get my program to run.
Is there a way just to type one command to run my program or can you run a C program without having a new .exe file being created?
I use gcc version gcc (MinGW.org GCC-6.3.0-1) 6.3.0
(Complete beginner with C)
CodePudding user response:
You can't run the .c
file directly - you have to compile it into an executable (using gcc
or whatever compiler). However, you don't have to compile it every time you want to run it - you only have to compile it after first creating it and after you make any changes. So you can run gcc
once, then run a.exe
multiple times.
You can name the executable something other than a.exe
if you wish using the -o
option:
gcc -o prog filename.c
./prog
CodePudding user response:
You could make a .bat file that does everything for you. For example:
build.bat
gcc %1.c -o %1.exe
%1.exe
This will build and run the file for you:
build hello.c
will compile and run hello.exe for you.