| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
Subject: Solution to Compiling and linking a static C++ library usable from C without linking libstdc++ Date: August 8, 2006 4:51:00 PM EDT Yesterday I wrote:
I figured out the solution--I guess it would be pretty easy if you simply used "otool -L" on the resulting executable to find the libraries to link to. Here it is: Using gcc or ld, prelink the object files into one big object file and then link those to libstdc++-static.a libgcc_s.1.dylib OR (in gcc library directory for your system) libgcc_eh.a libSystem.B.dylib NOTE: if you pass the flag -shared-libgcc to gcc, -lgcc_s.1 and -lSystem.B are added automatically (-static-libgcc does not work because Apple ships the system libraries without crt0.o--you will get a linker error). If you link to libgcc_s.1.dylib, you will have to link any executable with both -lgcc_s.1 and -lSystem.B . If you link to the static library libgcc_eh.a (on my computer it is in the directory /usr/lib/gcc/powerpc-apple-darwin8/4.0.1 ), you will only have to link the executable with -lSystem.B.dylib . The disadvantages of static linking are: -your resulting library is huge: almost 3MB larger than it would normally be; -if your executable links to any other C++ libraries, the stdc++ code is duplicated, not shared The advantages (and necessity) of static linking are: -executables (or other libraries) linked to your static C++/C library are stand-alone (you don't have to package programs with that library for user installs)--this was necessary for my purposes because the C++ code was going into a RunTime System (RTS): *every* executable would have to come packaged with an extra dynamic library for something that should be part of the RTS; -the linking process is much simpler for autotools (configure, make) builds, since the links to -lSystem.B and -lgcc_s.1 may go anywhere on the command line (you do not have to pass them at the end, as you do with -lstdc++-static). Pete |
_______________________________________________ Do not post admin requests to the list. They will be ignored. Unix-porting mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/unix-porting/email@hidden This email sent to email@hidden
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.