I use GCC compiler to compile and run C program on CMD.
When I compile C program using command gcc hello.c it creates an executable file file with name a.exe but when I use IDE it uses the name same as .c file as hello.exe.
Is it possible to create .exe file name same as .c file on CMD?
Asked
Active
Viewed 5,965 times
0
Joe
- 7,378
- 4
- 37
- 54
Abhishek Kumar
- 125
- 3
- 10
3 Answers
3
You have to specify the name of the executable
gcc -c hello.c // compiling
gcc -o hello hello.o // linking
^------------------------- name of the executable
you can do the compiling and the linking in one command
gcc -o hello hello.c
^------------------------- name of the executable
Martin Chekurov
- 733
- 4
- 15
0
You need to understand the syntax of output. Following is the description of the command:
$ gcc [options] [source files] [object files] -o output file
In your case you should execute the commands as following:
$ gcc myfile.c -o myfile
$ ./myfile
For more descriptions and more optimized ways refer to the following url: http://www.rapidtables.com/code/linux/gcc/gcc-o.htm
Ali Sajid
- 3,964
- 5
- 18
- 33