Reputation: 1205
When working with a large codebase, I've seen when certain object is being used, that object's header file is included. At other times that object's library is linked in the make file.
What is the reason for doing one or the other. If they have access to the source code, why not include all files whose object you are using instead of linking into their lib *.a files?
edit: made it clear based on first comment. It was a confusing statement
Upvotes: 1
Views: 1239
Reputation: 60004
One good argument for use of libraries it's that can be used more easily: to compile large codebases, all the right dependencies must be available, and there could be specific steps required, not relevant for the task at hand. And of course, the compile time it's cut away.
Upvotes: 0
Reputation: 6846
There isn't necessarily a one-to-one relationship between header files and binaries. In fact, there quite commonly isn't. For example, just because you see foo.h being included doesn't necessarily mean there's going to be a foo.obj or foo.lib. The reverse is also true; ie, you might see foo.lib being linked but there is no foo.h.
Using Windows as an example, you need quite a few header files to use anything found in kernel32.lib, but there is no kernel32.h.
Upvotes: 0
Reputation: 153909
Normally, you need to do both. Header files tell the compiler what functions are available, and what they look like. They have to be present when you compile. Libraries contain the implementation, and must be linked with the application in order for the compiler generated calls to work.
In a few rare cases, the "library" may consist of just header files; C++ still requires the implementation of a template to be present in the header, and not in a library, so a library which consists of nothing but templates may be header-only. In such cases, it is sufficient to include the headers; there's nothing more to link. (Of course, such libraries drive compile times through the roof.)
Upvotes: 4