You don't compile header files. You just include them in your code when you need them. For example, the usual "Hello World" program needs the header file [tt]stdio.h[/tt]. So you would use it as follows...
[tt]
/* hello.c */
Generally you should not compile any header files even user writen. Of cause you can put function implementation in header file and then you have to compile it, but this is WRONG design and you will not be able to include this file anywere, cause you will have double function difinitions during the linking.
There is a lot of way to messed up your programm, so just don't do it and do not try to make normal source file .c file looks like a header file.
You still don't compile header files. Header files don't, and shouldn't have executable code in them. They are for things like definitions, constants, function prototypes and such. If you have your own user written header file, you include it in your code with the following...
[tt]
#include "myheader.h"
[/tt]
The quotes make the preprocessor look for the header file exactly where you say, and not in the normal header directories.
The [tt]#include[/tt] statement causes the preprocessor to bring in the header file at that point, so it will be compiled when the module including it gets compiled.
Also, if you have executable statements in your header file, this should not be a header file. This is a misuse of what a header file is.
When you use precompiled headers (for example MS C++, and HP aCC support it) you don't compile it directly anyway. You still have to create .c file and include your common header file and then compile it. But I am agree it's not a normal object file since there will be only empty declarations, so in a way you are compiling header files.
It's more like saving the state of the compiler after it has processed the contents of a header file (or several), then using that state as a starting point for all files that include that header.
A more correct term would be something like preprocessed header or preparsed header.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.