Thread: Precompiled headers

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    16

    Precompiled headers

    I'm writing a small but useful C library (function is irrelevant). I'm experienced at programming but not more administrative things like autotools (I know what I've needed to know so far). How would I take my C file of library code and make a precompiled header, so that any implementing program could just go

    Code:
    #include <myLibrary.h>
    instead of having to specify the local C file during compilation? I want this to be somewhat professional and part of that is having a professional interface for implementing Unix developers.

    Thanks for your responses

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    This is the essence of what you do to create a static library

    gcc -c myLibrary.c
    ar crs libmyLibrary.a myLibrary.o

    The first line compiles your library code to an object file. You can have as many of these as you like depending on what your library is supposed to do.
    The second line then adds all the objects which make up the library.

    You then give myLibrary.h and libmyLibrary.a to whoever.

    So to use your library, someone might do
    gcc -I/path/to/h prog.c -L/path/to/lib -lmyLibrary
    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.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    16
    Thank you very much. There's knowing how internal combustion works from a physics standpoint, and then there's knowing how to change the oil ... I'm still working on the latter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Precompiled header question
    By donglee in forum C++ Programming
    Replies: 13
    Last Post: 01-22-2009, 01:23 AM
  2. How to use precompiled headers in GCC?
    By jutirain in forum C++ Programming
    Replies: 0
    Last Post: 02-04-2008, 10:19 PM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. Precompiled Headers, are they necessary?
    By XenoCodex Admin in forum C++ Programming
    Replies: 2
    Last Post: 06-23-2002, 02:09 PM
  5. Precompiled Headers
    By Bazz in forum C++ Programming
    Replies: 2
    Last Post: 02-12-2002, 08:57 AM