What is the difference between - 1) Preprocessor,linker, 2)Header file,library? Is my understanding correct?

前端 未结 3 1368
悲&欢浪女
悲&欢浪女 2020-12-13 05:20

Okay, until this morning I was thoroughly confused between these terms. I guess I have got the difference, hopefully.

Firstly, the confusion was that since the prepr

3条回答
  •  甜味超标
    2020-12-13 06:14

    This is an extremely common source of confusion. I think the easiest way to understand what's happening is to take a simple example. Forget about libraries for a moment and consider the following:

    $ cat main.c
    extern int foo( void );
    int main( void ) { return foo(); }
    $ cat foo.c
    int foo( void ) { return 0; }
    $ cc -c main.c
    $ cc -c foo.c
    $ cc main.o foo.o
    

    The declaration extern int foo( void ) is performing exactly the same function as the header file of a library. foo.o is performing the function of the library. If you understand this example, and why neither cc main.c nor cc main.o work, then you understand the difference between header files and libraries.

提交回复
热议问题