September 15th, 2012, 01:24 PM
How to link a library in C !
Well ! Hi, I want to learn how can I link a library to a programm..
I mean what do I have to write to terminal ...and if
#include "library.h" is needed !
Thanks in advance ..
September 15th, 2012, 04:40 PM
[/code] are essential for python code and Makefiles!
September 15th, 2012, 06:22 PM
Do you know the difference between source code and object code? Source code is human-readable, whereas object code is machine-readable. It's the compiler's job to translate human-readable source code into machine-readable object code. The linker then takes the object files that the compiler creates and splices them together into an executable which you can run.
A library file is a special kind of object file. It's a collection of pre-compiled code that you don't need to compile yourself -- that also allows a programmer to sell his library and still protect his source code from piracy. But for you to know how to use that library, he gives you a header file (eg, your example "library.h") that tells your compiler what the library functions are.
Therefore, you need to #include the header file so that the compiler will understand the function calls in your source file. And then you need to tell the linker to link in the library file.
Now, how you link in that library file depends on your development environment, which you probably call your "compiler". In GUI integrated development environments (IDEs), you will have created a "project" to which you added your source files and through which you add the libraries you want to link in. Until you tell us what development environment you're using, we cannot possibly give you an specific instructions.
If you're using gcc from the command line, here's how you would link in a library file called "Library.a":
gcc -Wall main.c second.c third.c -o myprog -lLibrary
September 20th, 2012, 11:33 PM
You should #include "libstatic.h", i.e. use the appropriate header file in your code (that's why your code doesn't compile) and include the path to your libstatic.a in the linker options as one of your input libraries. click dapfor. com/en/net-suite/net-grid/tutorial/data-types
for more information
Comments on this post
Last edited by Scorpions4ever; September 21st, 2012 at 01:14 AM.