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?
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.
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)).
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.
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.
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.