gcc -c xx.c explain the options

-cOption indicates that the compiler, assembler specified source file (that is, compile the source file), but do not link to it. Use -coptions for each source file can be compiled into corresponding object files.

Target file is an intermediate file or temporary file, if you do not set this option, gcc generally does not retain the object files, executable files generated after completion automatically deleted.
Note that using -coption means only compile the source file, without links, therefore, to link errors can not be found.

The following example demonstrates the gcc compiler in use -cwhen the options will not find a link error.

1) write the following two source files.

Func.c defined in func_a () function:

    #include <stdio.h>
    void func_a(){
        printf("FUNC_A\n");
    }

 Call func_a in main.c in () and func_b () function:

    #include <stdio.h>
    int main(void)
    {
        func_a();
        func_b();
        return 0;
    }

func_b () function is not defined, so the link will generate an error (no error is generated at compile time).

2) Use -coption to compile two source files, as follows:

$gcc -c func.c main.c

The compiler does not output any error messages.

3) do not use -cthe option to compile two source files:

$gcc func.c main.c 

You see the following error message:

/ tmp / ccLlOhvh.o: the function 'main' in: 
main.c :( text. + 0x14 ): undefined references to 'func_B' 
collect2 to: Error: ld returned 1

Not finding func_b (defined) function, so the link error occurred.

Guess you like

Origin www.cnblogs.com/liuzhenbo/p/11030200.html