Thread: Two questions (Linking Libraries and Creating Them)

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Two questions (Linking Libraries and Creating Them)

    1) Anyone know of a way to statically link only certain libraries? Reason this came up is because I am using the CGIC library and it requires use of a shared library. Since my web host does not have them I have to use the -static parameter with gcc. This in turns brings in all the other libraries which brings the file size to about 450k.

    2) How do you create a library from multiple object files in Linux?

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    for number 1:
    I would guess
    gcc -o test -static -lsomelib -shared -lsomeotherlib
    for number 2:
    gcc -c -fPIC test1.c
    gcc -c -fPIC test2.c
    gcc -shared -fPIC -o libtest.so test1.o test2.o
    Last edited by chrismiceli; 03-10-2004 at 10:37 PM.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    static library from several object files is simply this:

    ar rc libLibName.a file1.o file2.o file3.o
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thanks FYB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  3. creating libraries in c
    By reallyfreakedou in forum C Programming
    Replies: 2
    Last Post: 03-31-2003, 12:12 PM
  4. creating libraries for c++
    By Klinerr1 in forum C++ Programming
    Replies: 33
    Last Post: 08-04-2002, 02:34 AM
  5. error LNK2001: unresolved external symbol
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 07-12-2002, 08:45 PM