If I create a static library in C++ in Linux such that a “.a” file is produced, how do I (or anyone else) use the library? For example, my library defines a class. I assume that it is not sufficient merely to provide the “.a” file, but also to provide a header file. How do I know what header files must be provided with the “.a” file?
For example, do I need to provide all header files that were included anywhere in the code for my library?
The technical reason for header files is to let the compiler know about names and sizes while compiling user code, so that it can arrange the user object’s layout.
That is the reason why
privatemember of public classes (note the the emphases: public, here, is not the keyword) must be exposed in headers.You can avoid to expose classes that are layed-out in the exposed parts only as pointers or references, since their actual instance will not leave in the resulting user object itself. In that case you can declare just the name.
You have -in substance- top provide to the user all the declarations that