0

I think library is just the implementation of header file I just got the gist of it by seeing library vs header file but here it is shown that container is library with many headers like vector,list etc.

So if i make two files one add.h with declarations of functions and add.cpp with definition of function add.cpp would be library.But is it possible to have more than one header's definition in a single library?

So basically my question is just what is stated in title and I would also like to make sure that I haven't misunderstood libraries and is that all there is to library?

Pratham Shah
  • 168
  • 1
  • 7

2 Answers2

3

A library is the compiled code (headers (*.h) + sources (*.cpp)). Such library can be linked to your executable. To use the defined functions/classes and such of these library, your compiler needs the declaration of them, which are provided by the headers. The headers are normally provided with the library (*.DLL on windows, *.so on UNIX for dynamic loaded libraries, *.lib on windows, *.a on UNIX for static libraries).

While compiling you have to specify where to find the included headers and also which libraries to link against.

But to summarize your question a library (normally) comes with multiple headers (could also be one) which declare the usable functions/classes of the library. With the headers your compiler knows the signatures of said functions, so he can compile the function calls.
In the link step, the linker links the said functions against the function calls in the "runnable" library.

RoQuOTriX
  • 2,871
  • 14
  • 25
  • So, library is .obj file which is created after compiling add.cpp? – Pratham Shah Apr 29 '20 at 11:20
  • 1
    No a *.obj is an object. One or more objects can either be a library or an executable, depends on what you tell your linker to do. To get a better understanding of that, you should look up, how c programs and libraries get compiled and linked – RoQuOTriX Apr 29 '20 at 11:22
  • Can you tell me where to look up like any good websites or books for documentations? – Pratham Shah Apr 29 '20 at 11:30
  • https://www.toptal.com/c-plus-plus/c-plus-plus-understanding-compilation https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work https://www.learncpp.com/cpp-tutorial/introduction-to-the-compiler-linker-and-libraries/ – RoQuOTriX Apr 29 '20 at 11:34
1

is it possible to have more than one header's definition in a single library?

Yes. If a library contains more than one function, then you can declare those functions in separate headers. This is in fact very common.

eerorika
  • 232,697
  • 12
  • 197
  • 326