Thread: Static library linkage

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    53

    Static library linkage

    To get rid from dynamic shared linkage i should rather link library as object file i.e.
    gcc <my_objects> /full/path/to/my_lib.a
    . And i wonder whether in this case some unneeded object files are really discarded as they use to be under linkage via "-l" flag. I suspect it's not case because of too large output binary.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Static linkage will always give you a bigger object file than dynamic linkage.

    If the library is well constructed (lots of individual modules), then you should only get what you need.

    You could try things like
    $ size a.out
    text data bss dec hex filename
    1542 520 16 2078 81e a.out
    $ ls -l a.out
    -rwxrwxr-x 1 sc sc 8480 2013-01-07 16:52 a.out
    $ strip a.out
    $ ls -l a.out
    -rwxrwxr-x 1 sc sc 6216 2013-01-08 18:53 a.out

    But bear in mind that a stripped executable is nigh on impossible to debug.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static library vs Dynamic library
    By Alegomaster in forum C Programming
    Replies: 5
    Last Post: 03-17-2011, 07:26 PM
  2. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  3. Get sense of internal linkage and external linkage
    By gandalf_bar in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2003, 05:57 AM
  4. help with static linkage error of member function
    By inandout in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2002, 11:20 AM
  5. static linkage problem
    By Sebastiani in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2002, 10:16 PM