Reputation: 61
Suppose there are 2 c program named abc.c and xyz.c . Now we want to work with the 2 executables at a time. So we change the name of the ./a.out using
gcc -g abc.c -o abc
gcc -g xyz.c -o xyz
Even gcc -o abc abc.c
works.
What does the -g
and -o
in the above commands specify or describe?
What is the significance of -g
and -o
in the command for renaming ./a.out file.
Thanks in advance.
Upvotes: 2
Views: 5312
Reputation: 5376
if we specify -g option while compiling, debugging symbols will be available in the output file which will be useful when you try to debug using GDB.
If we won't specify -o option, the output will be placed in default a.out file. So if we run
gcc a.c - output will be in a.out
gcc b.c - output is a.out which is replacing old a.out file
If you want the output not to be a.out file, you can give -o option while compiling
gcc abc.c -o a
-o and -g options are not related.
Upvotes: 0
Reputation: 117
-g starts becoming useful once you use debuggers such as gdb and lldb. When you attach to a running program and advancing one line at a time printing/altering the state as it changes.
Upvotes: 0
Reputation: 780889
-g
means to leave debugging information in the output file, it's unrelated to renaming.
-o
means to put the result in the specified file instead of the default filename (abc.o
for object files, a.out
for linked executable files).
Upvotes: 2
Reputation: 62063
From https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html:
-g Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information.
-o file Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.
Upvotes: 1