1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Rep Power

    Post 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 ..
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Rep Power
    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
  6. #4
  7. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Rep Power


    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

    • Scorpions4ever disagrees : Cutting/pasting content from other websites to make you look like you know what you're talking about won't work here. I've already caught you 3 times. One more incident or an attempted link drop and you're out.
    Last edited by Scorpions4ever; September 21st, 2012 at 01:14 AM.

IMN logo majestic logo threadwatch logo seochat tools logo