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

This is a discussion on How to compile with libraries (*.a) with gcc? within the Linux Programming forums, part of the Platform Specific Boards category; I'm fairly new at this gcc stuff. So I successfully compiled a set of libraries from the source. How do ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 09: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, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21