I have several header files in a library: header1.h, header2.h...
I also have a general header file for the library: mylib.h
I want the user to import the main.h file and get access to only some of the functions in the other header files.
For example, in the library:
// header1.h
void a(void);
void b(void);
-
// mylib.h
// I can't use this:
#include "header1.h"
// because it would make b function visible.
// Link to function a ????????
And in my main program:
// main.c
#include "mylib.h"
int main(void) {
a(); // Visible: no problem
b(); // Not visible: error
return 0;
}
Separate function prototypes into different headers, depending on whether they should be "visible"*1 or not (but be "internal").
header1_internal.hheader1.hheader2_internal.hheader2.hInclude into the
*_internal.hheaders the related*.hheader.Include the
*_internal.hheaders into your lib's related modules.Do not include any
*_internal.hintomylib.h.*1: Please note that even when not providing a prototype this way the user might very well craft his/her own prototype and then link the function from
mylib. So the functions not prototyped aren't unaccessible.