Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does .h, .lib & .dll works together

To use FreeGlut librarie function, I had to do the following,

  • Added freeglut.h as a Header File
  • Added freeGlut.lib as a Resources File
  • Copied freeGlut.dll to my windows/SysWOW64 folder

But, how this whole system(.h, .lib & .dll) is interrelated with each other?

I know, the most basic thing is add a header file with class declaration and write the body on its respective source file. Finally include the header file to you main app.

like image 543
Quazi Irfan Avatar asked Jun 20 '11 18:06

Quazi Irfan


People also ask

How does a .h file work?

A header file is a file containing C declarations and macro definitions (see Macros) to be shared between several source files. You request the use of a header file in your program by including it, with the C preprocessing directive ' #include '.

Do .h files get compiled?

Only source files are passed to the compiler (to preprocess and compile it). Header files aren't passed to the compiler. Instead, they are included from source files.

How do .h files work C++?

Header files are used in C++ so that you don't have to write the code for every single thing. It helps to reduce the complexity and number of lines of code. It also gives you the benefit of reusing the functions that are declared in header files to different .

What do .LIB files do?

lib file contains all the code and data for the library. The linker then identifies the bits it needs and puts them in the final executable. For a dynamic library, the . lib file contains a list of the exported functions and data elements from the library, and information about which DLL they came from.


1 Answers

You have to include the header files so that the compiler understands the declarations of various types and functions that are exposed/used by the library.

The library files(lib or dll) contain the object code to which the code using the library links to.

for lib the linkage is static and happens at compile time.Using a static library(lib) causes the size of your executable to increase because the entire lib is linked in to your program.

for dll the linkage is dynamic and calls are evaluated at runtime.When using dll the size of your executable does not increase because the dll's are linked at runtime and you usually need to place them at predefined paths so that they can be linked at runtime.

Advantage of static library over dll is that your executable which uses the lib is standalone while in case of dll, the dll needs to be present at a predefined path whil running the executable which uses it.

like image 121
Alok Save Avatar answered Sep 18 '22 19:09

Alok Save