Create and use a library

Discussion in 'C Programming' started by Gattaca, Jun 9, 2004.

  1. Gattaca

    Gattaca Guest

    Hello,

    1. How can I create a personnal library (with my own functions) ?
    2. How can I use it ?
    I know that in my source code I will have something like
    #include "mylib.h"

    But how to make a link between mylib.h and the library compiled ?

    Thanks

    Note that I read the FAQ first. I didn't find answer to my questions.
    Gattaca, Jun 9, 2004
    #1
    1. Advertising

  2. Gattaca

    Case - Guest

    Gattaca wrote:
    > Hello,
    >
    > 1. How can I create a personnal library (with my own functions) ?
    > 2. How can I use it ?
    > I know that in my source code I will have something like
    > #include "mylib.h"
    >
    > But how to make a link between mylib.h and the library compiled ?


    a. Place all functions in a file with name "mylib.c".
    b. Place all function declarations and other stuff (types,
    macro's, #defined constants, ...) in the "mylib.h".
    c. As you say, #include "mylib.n" in every source that
    uses one or more of these library functions.
    d. Compile "mylib.c", "source.c", ...
    e. Link the object files into a program.

    Step d. and e. can be done with one action/command for example:

    cc source.c mylib.c -o myprog

    This will invoke the linker as well. When you compile "source.c"
    the compiler sees there are external functions (declared in "mylib.h")
    and marks calls to them as unresolved. The linker makes a list
    of all these unresolved externals and tries to find a match in
    all object files it currently is processing. When there's a
    match it fill in the right 'address' for each external.

    HTH
    Case -, Jun 9, 2004
    #2
    1. Advertising

  3. Gattaca

    Gattaca Guest

    Create and use a library (new)

    Gattaca a écrit :
    Sorry but I assume I was not clear enought.
    When I said I wanted to create a personnal library It was rather
    -> How can I create a personnal compiled library (not a C file)?
    In order to keep my source code secret and to do "a public interface"
    with a "mylib.h" header file.

    Thanks


    > Hello,
    >
    > 1. How can I create a personnal library (with my own functions) ?
    > 2. How can I use it ?
    > I know that in my source code I will have something like
    > #include "mylib.h"
    >
    > But how to make a link between mylib.h and the library compiled ?
    >
    > Thanks
    >
    > Note that I read the FAQ first. I didn't find answer to my questions.
    Gattaca, Jun 9, 2004
    #3
  4. Gattaca

    Andrew Guest

    Re: Create and use a library (new)

    On Wed, 09 Jun 2004 16:32:24 +0200, Gattaca <>
    wrote:

    >Gattaca a écrit :
    >Sorry but I assume I was not clear enought.
    >When I said I wanted to create a personnal library It was rather
    >-> How can I create a personnal compiled library (not a C file)?
    > In order to keep my source code secret and to do "a public interface"
    > with a "mylib.h" header file.
    >


    [snip]

    You would be better off asking this question in a vendor-specific
    group, as Standard C has no concept of a "personnal library".

    To point you in the right direction, you need to check your
    implementation's documentation on its library manager (for MSVC this
    is "lib.exe", for GNU C this is "ar"). You use the library manager to
    collect all the object files generated from your TU's into one big
    file. To use it, you need to let your linker know that it can check
    out said library for otherwise unresolved references. Again, this is
    implementation specific, and is entirely off-topic here.

    --
    Andrew
    Andrew, Jun 9, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mythran
    Replies:
    0
    Views:
    2,417
    Mythran
    Aug 24, 2004
  2. TBass
    Replies:
    5
    Views:
    371
    Ben Pope
    Apr 4, 2006
  3. Sunny
    Replies:
    5
    Views:
    360
    Sunny
    Mar 30, 2007
  4. Krithika San
    Replies:
    3
    Views:
    333
    Marnen Laibow-Koser
    Nov 14, 2009
  5. Simon Hardy-Francis
    Replies:
    2
    Views:
    59
    Rustom Mody
    Mar 23, 2014
Loading...

Share This Page