Do I need to compile the header files in a C program?

前端 未结 5 890
生来不讨喜
生来不讨喜 2020-12-23 12:32

Sometimes I see someone compile a C program like this:

gcc -o hello hello.c hello.h

As I know, we just need to put the header files into the C p

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 12:57

    I think we do need preprocess(maybe NOT call the compile) the head file. Because from my understanding, during the compile stage, the head file should be included in c file. For example, in test.h we have

    typedef enum{
        a,
        b,
        c
    }test_t
    

    and in test.c we have

    void foo()
    {
        test_t test;
        ...
    }
    

    during the compile, i think the compiler will put the code in head file and c file together and code in head file will be pre-processed and substitute the code in c file. Meanwhile, we'd better to define the include path in makefile.

提交回复
热议问题