*nix GURUS: Using ar command

Discussion in 'OT Technology' started by rpark, Apr 26, 2005.

  1. rpark

    rpark New Member

    Joined:
    Apr 9, 2005
    Messages:
    1,082
    Likes Received:
    0
    Location:
    Isla Vista, California
    Okay, this is one simple step of one of my comp sci classes that i cannot figure out.

    So i wrote this library file called tman.c and used gcc to make it tman.o

    now i have to use the ar command to make it into a library file called libtman.a

    I have no clue how to use the ar command and the man pages are never helpful to me. Can someone explain how to make this a libtman.a?

    On top of that, I'm kind of new to C but do you use the libtman.a as u would a normal header file?

    Code:
    #include "libtman.a"
    will that suffice?


    cliff:
    gotta make a file.o to a file.a using ar.
    then must use file.a to program.
    howto?
     
  2. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    ar -r libtman.a tman.o

    At least that's how it works on the version of linux I'm using.

    You don't link to libraries by including the library file as a header. You need to specify the library as a command line option to the compiler or linker. But, you should have a header file that prototypes any functions you wish to export from the library.

    So, the final compile step would look something like:

    gcc -o myexe myprog.o -L . -l tman

    This will create an executable file named myexe by linking together the myprog.o file (previously compiled from myprog.c, for example) and the libtman.a library. The -L specifies the library search path. It's telling the linker to look for libraries in the current directory ('.'). The -l specifies the library name. You don't give it the name of the library file, just the library name. The linker will look for a file named lib<library name>.a.
     
  3. rpark

    rpark New Member

    Joined:
    Apr 9, 2005
    Messages:
    1,082
    Likes Received:
    0
    Location:
    Isla Vista, California
    THANKS! :bowdown:
     

Share This Page