Include the header files in .lib

I am learning about .lib (static library) files and I have a big question:
When we make a .lib project, we include the header files there, but it looks like only the definitions go into the final .lib file and not the declaration.

My question is that is there a way to include the declaration in the .lib file so that when I use the .lib in another project, once I include the .lib file through linker, there will be no need to include a header file in the code?

I appreciate your help.
That's not how it works, sorry. You need the header to tell the compiler what functions are defined. Otherwise, you won't know until the linking stage, which would give you many compiler errors about functions it doesn't know about.
closed account (zb0S216C)
I do believe that the source modules included within the project make the library itself. The header modules alone cannot make the library. Like Zhuge said, without those class and/or function definitions, you're going to receive unresolved external symbol errors. However, you can avoid the library altogether if your cram everything into the header module (s) which I don't recommend (it also results in a larger build (larger executable)).

Wazzak
I see. So, does that mean when making .lib files, the header files in the static library projects don't play any role?

I eliminated them from my project and the produced .lib file worked just the same!

Does that mean we don't have to include the header files in the static library projects?



Thanks a lot for your help
closed account (zb0S216C)
Yes, you do. The header modules contain the class and/or function declarations while the source modules hold the definitions of the classes and/or functions. You're required to include both header and source modules into your project when you build it.

Wazzak
But I eliminated the header file and it worked!

when you contain the declarations in the header file, what should we have that in the lib file again?
closed account (zb0S216C)
Here's how it goes:

Libraries consist of header modules and source modules. The header modules hold the declarations of classes and functions. The source modules contain the definitions of the classes and functions within the header modules. When the library is built, you use the header modules to access the definitions within the library. Without the header modules, you won't be able to use the library.


Wazzak
So, what might have my lib file work then? while there was no header file while building it?

Thanks
closed account (zb0S216C)
soheilghafurian wrote:
what might have my lib file work then?

I'm sorry but I don't understand.

soheilghafurian wrote:
while there was no header file while building it?

How're you supposed to access the classes and functions within the library if you haven't got a header module with their declarations?

Wazzak
Oh, sorry. I typed it wrong.
What has happened is I removed the header file from my static library project and built again, then I used the produced .lib file instead of one which was made from a project which included the header file. But the result was the same and it worked. That's why I came to the conclusion that the header file in .lib might be redundant.
Topic archived. No new replies allowed.