Thread: How to compile with libraries (*.a) with gcc?

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    3

    How to compile with libraries (*.a) with gcc?

    I'm fairly new at this gcc stuff. So I successfully compiled a set of libraries from the source. How do I use them in my program? Do I need to include the library headers in my program? What arguments/options do I pass to gcc?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Say for example your library is in
    /home/me/work/thing/lib/libthingy.a
    and it's corresponding header file is in
    /home/me/work/thing/inc/thingy.h

    To compile something using those, say
    Code:
    #include <thingy.h>
    int main ( ) {
        doAThing();
        return 0;
    }
    You would compile with
    gcc -I/home/me/work/thing/inc main.c -L/home/me/work/thing/lib -lthingy
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc asm code syntax
    By Uberapa in forum C Programming
    Replies: 4
    Last Post: 06-15-2007, 01:16 AM
  2. gcc not for C++?
    By tin in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2004, 08:26 AM
  3. GCC bool undefined
    By Stack Overflow in forum Linux Programming
    Replies: 3
    Last Post: 07-06-2004, 12:54 PM
  4. Replies: 4
    Last Post: 11-14-2001, 10:28 AM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 02:32 AM