What is the difference between header files and library files? More specifically, what roles do they have in compilation/linking process?
What is the difference between header files and library files? More specifically, what roles do they have in compilation/linking process?
Clear the mines from our Shazbot!
Get the enemy Shazbot!
If your fx. look into an header file, they contain a lot of definitions and such, which refers to a (as far as I remember, somebodt correct me if I'm wrong please ) to a library file, which then knows what to do. When you fx. call a sinus(sin) function from the header file math.h..
That is fx. why you can't just copy & paste a header file from one compile to another and make it work, because it's the library that really has the code and not the header file...
It's also possible to make your own header file, if you want to make your code more (wrong word, but can't think of another) "pure"/"readable"..
Some library file examples could be glut.lib which again holds some new functions for GLUT programming or opengl.lib as another..
Hope this helps you a little?? If not, just write again
-//Marc Poulsen -//MipZhaP
He sat down, he programmed, he got an error...
what is fx.?
Clear the mines from our Shazbot!
Get the enemy Shazbot!
Header file declares things - it says compiler that things you use in code (functions, defined names etc.) do exist, that they are defined, somewhere. Then, compiler can say your code is syntactically correct.
Later, such things as functions' bodies are expected to be found somewhere, so that linker can put your code together. So it looks for 'bodies' of those functions declared in headers, either in your provided source files or in specified libs (they are, basically, something like precompiled pieces of code). Function bodies in libs are linked with their respective calls in your source files.
Hope this does not collide with MipZhaP's post much and clears it a bit
fx = for example
lobo, thx for your support It doesn't conflict with what I wrote
-//Marc Poulsen -//MipZhaP
He sat down, he programmed, he got an error...
from what I understand from the explination, header files contain function declarations/prototypes and library files contain function definitions?
Clear the mines from our Shazbot!
Get the enemy Shazbot!
Correct.
Thank you sean, could that be your shortest post?
Cool! Some other questions:
1) Why is there both a library and a header file? Couldn't the header contain the function definitions as well?
2) Does the library file contain only the function definitions which are used in your source code? If so, how does it get created with only the definitions of the functions used?
edit: The answers have come to me!
Please ignore question #1, and #2.
Last edited by jrahhali; 08-22-2004 at 10:33 PM.
Clear the mines from our Shazbot!
Get the enemy Shazbot!
1) I suppose so but that's very bad practice. All the commercial (and open source, mind you) libraries are packaged as a library of code and a header of the prototypes the user will need to know.
pre-edit-edit: Just saw your edit...
I examined the header iostream.h (turbo c++) and i was trying to find a referal to a library file but i couldn't.MipZhaP
a header file, they contain a lot of definitions and such, which refers to a...library file, which then knows what to do.
edit: Why?
re-edit: I just went on a chat room, and I was told that the linker searches through all the library files for the definitions, not just one that the header file specifies. Which answer is right (refering to the quote above)?
Last edited by jrahhali; 08-23-2004 at 11:28 PM.
Clear the mines from our Shazbot!
Get the enemy Shazbot!