0

What's difference between library and header files?are header files called library too ?

library and header files differences

13th Aug 2018, 9:19 AM
Saeed Vahid
Saeed Vahid - avatar
5 Respuestas
+ 5
saeed The same as picking a book (header) from a library.
13th Aug 2018, 9:43 AM
Manual
Manual - avatar
+ 1
An header file give to compiler basic (and important) information about functions (and classes) like return type, arguments numbers and types necessary for check correct call to they before linking happen... Libraries contains implementations that will linked at after stage
13th Aug 2018, 10:02 AM
KrOW
KrOW - avatar
+ 1
thank you but does it mean that for example cmath.h header file is one part of a library ? if yes what's that library's name and it's extention?
13th Aug 2018, 7:21 PM
Saeed Vahid
Saeed Vahid - avatar
+ 1
Because (usually) an header its necessary for use a lib.... Compilation its a process subdivided in more subprocess, two of these are important in this context... The first is when compiler process all .c files and encounter an symbol... It check if this symbol is valid (is defined if is a constant/macro or check parameter type/count for a function call) but in this stage it dont resolve symbols from multiple executable objects (any .c file will be compiled in an object file)... In a successive stage, at linking stage precisely, linker will resolve these unresolved file searching for implementation in libs (where search depends on your compiler settings and can be customized also). In practice headers tell to first pass how symbol is defined (an description) while lib its necessary to second pass (linking) to resolve these definitions and link/import in final executable all external code (defined in lib).
13th Aug 2018, 7:53 PM
KrOW
KrOW - avatar
+ 1
Futhermore you can have 10 headers and one lib (or one header and 10 lib) but important its than if you want use an external code (from lib in your code) you have to make avaible to first pass (thanks to header file) and to second pass (thanks to lib file)... If you dont provide an header file (or a declaration in same .c file of symbol that you want use) you will get an unresolved symbol error at first stage (because it dont know if that symbol is valid) while if you dont make avaible the lib with implementations you wil get an unresolved external symbol error at second stage (because linker dont know how resolve symbol references)
13th Aug 2018, 7:57 PM
KrOW
KrOW - avatar