Reputation: 1039
I am working on a comprehensive long-term C programming project that will require a modular programming approach. As part of the design, libraries will be created, so I wanted to confirm a true/false interpretation of header file organization:
Problem
Suppose that you are creating a library. After thinking it over, you have decided that the ultimate library you wish to conceive, aka "godzilla", should consist of two individual C files that bind to a header file. In this header file there will exist the function declarations; for example:
// offense.c
void attack_city(uint32_t force); // (in Newtons) - capable of a LOT of force!
...
// measure.c
void measure_effect(void);
...
Here is a basic network diagram you drew:
Because both force.c
and measure.c
includes godzilla.h
, everything will be referenced from this header file and included in the compilation process, correct?
EDIT
Application: ARM microprocessor
Upvotes: 0
Views: 1800
Reputation: 16802
All the header file does is tell the compiler what functions are available and how they should be called (how many parameters of what types, and the return values).
It is the linker (or librarian, when creating a library rather than an executable) which brings the multiple object files which result from compiling each of the .c files. So you need to tell the compiler (for example on the command-line, through an IDE or Makefile) all the c files that you want it to compile.
Upvotes: 1
Reputation: 36082
There is no implicit "binding" between header(s) and a .lib-file
In order to create a library you need to explicit tell what compiled files (.obj/.o) you wish to put in, the linker creates the library regardless of header.
Headers do come in play when linking if the different .obj-files share data or call one another but there is nothing implicit about that.
Upvotes: 0
Reputation: 7598
You should become familiar with how the linking works.
Normally when you compile you create object files with some unresolved references, that will be resolved by the linker, that will create the binary. Some of these references can point to external libraries, and will be left "unresolved" and will be resolved at run-time.
An header file just gives the compiler the signature of the function (gives no information on where to find the actual implementation) so it will know how to pass the arguments to the function. If the function is not defined in the same module the linker will need to find it. I have no clue of which system you are using so I can't help you.
And in general before starting to write a C library you should understand these concepts very well, or you will make a crappy library that will change ABI at every minor release and will have a bad karma for that.
Upvotes: 2