including and linking libraries

Dec 14, 2010 at 1:50am
Hi,

What's the difference between including a library and linking to a library?

I have seen some programs include a library. Could they have done with just linking? And viceversa?

Thanks.
Dec 14, 2010 at 12:38pm
Including a library generally refers to when you '#include' a header file which links to the whole source code and is compiled when you compile your program.

When you link a library you also include a header file which contains function/variable declarations (but typically not definitions), and then you also tell the compiler that you are linking a library (usually with a command line argument) This tells the compiler to look in some predetermined folder (or a folder that you specify) for the library that you specified which is in binary form (meaning it is already compiled and ready to use). Your program will know how to use the binary because of the include file which you added which contains a list of all the functions and variables contained within that library, however you can not see the source code because it is binary form already.

This is done to allow libraries of code to be used for many applications, rather than having multiple copies of the library for every application which uses it. There are other pros and cons for each method but you can surely find them with a quick google search :)
Last edited on Dec 14, 2010 at 12:42pm
Dec 14, 2010 at 7:06pm
Thanks aatwo!
Dec 15, 2010 at 9:04am
you're welcome :)
Topic archived. No new replies allowed.