What the -c option does in GCC

Does anyone know what the flag does -c

in gcc

?

For example, what's the difference between

gcc -c output0.c
vs gcc output0.c

      

I know the second is doing the file .a

, but I am not doing that file .a

.

And what does it do -o

in

gcc output0.o -o output0

      

Is it just to name the output file correctly?

+3


source to share


3 answers


-c

Compile or create source files, but don't link. The linking stage is simply not done. The end result is in the form of an object file for each source file.

     

By default, the object file name for the source file is generated by replacing the suffix .c, .i, .s, etc., with .o. Unrecognized input files that do not require compilation or assembly are ignored.

-o file

Put the output in a file. This is applicable regardless of whatever kind of output the output is, whether it is an executable file, a file object, an assembler file, or preprocessed C code. If -o is not specified by default, place the executable in a.out file, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.



More can be found in the GCC man page

+6


source


-c instructs gcc to only compile the source file to an .o (object) file, but does not invoke the linker.

In a project that contains many .c files, it is common to compile all the .c files to .o files first and then link everything together with the libraries.



-c Compile or build source files, but do not link them. This link fails. The end result is represented as a file object for each source file.

      By default, the object file name for a source file is made by replacing the suffix >.c, .i, .s, etc., with .o.

      Unrecognized input files, not requiring compilation or assembly, are ignored.

      

+2


source


From man gcc

:

...

-c Compile or build source files, but do not link them. The linking step is simply not done. The end result is in the form of an object file for each source file.

By default, the object file name for the source file is generated by replacing the suffix .c, .i, .s, etc., with .o.

Unrecognized input files that do not require compilation or assembly are ignored.

...

+1


source







All Articles