Creating a static library that depends on other libraries

This is a discussion on Creating a static library that depends on other libraries within the C++ Programming forums, part of the General Programming Boards category; I'm certain this can't be the easiest way, but this is what I did: Code: - created a directory for ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    14

    Creating a static library that depends on other libraries

    I'm certain this can't be the easiest way, but this is what I did:

    Code:
    - created a directory for each of the libraries I needed, for example:
       - ./dep/curl, ./dep/ssl, etc...
    - copied to the above dirs the corresponding static libraries
    - unarchived each library, for example:
       - cd ./dep/curl && ar vx libcurl.a
    - Compiled my static library I created to object files
    - Executed the following command to complete the new static library:
       - ar rcs mylib.a *.o ./dep/curl/*.o ./dep/ssl/*.o (and so on with the other dependencies)
    This worked and created a static library I am successfully using. I'm just wondering if there is a better way to do this while still not having to rely on any of the dependencies beign present on the box that will use the static library I created. Thanks.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,252
    Quote Originally Posted by maverickbu View Post
    This worked and created a static library I am successfully using. I'm just wondering if there is a better way to do this while still not having to rely on any of the dependencies beign present on the box that will use the static library I created. Thanks.
    First be aware you may be violating the licenses of those libraries by doing this, since you are producing a binary distribution. But assuming you've worked that out (have a plan to distribute source code), and if you're going to be doing a binary distribution anyway, why not just distribute the independent .a files? There's no need to merge them together.

    If this is for your own use (you won't distribute it), then I guess what you're doing here is probably the best way to go. By exploding and then recreating the archive you maintain the identity of the individual object files, which makes a huge difference in linker efficiency as well as smaller final binaries.

    If you're looking for a single command to "cook" the whole thing down into a single archive, the following comes close:

    Code:
    ld --whole-archive *.o ./dep/curl/libcurl.a ./dep/ssl/libssl.a [etc] -r -o unified.o
    This rolls every symbol in all the listed objects and archives into a single, huge object file. This is probably NOT a good way to do this though.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Like brewbuck, I'm a bit confused as to the purpose of this. Just adding a bunch of libraries into a megalibrary serves very little purpose, and just makes a huge unwieldly library - what's the point?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. uploading file to http server via multipart form data
    By Dynamo in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2008, 04:36 AM
  2. GCC: Compiling with both static and shared libraries
    By eatwithaspork in forum C Programming
    Replies: 4
    Last Post: 06-23-2008, 01:48 PM
  3. Templates from DLL or static library problem
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2008, 12:49 AM
  4. Creating my own library
    By gozlan in forum C Programming
    Replies: 8
    Last Post: 10-14-2002, 11:11 PM
  5. Creating extra library
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2002, 05:48 PM

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