Linker flags and archives
Author: Samuel Williams When: Monday, 27 April 2009April 2009
May 2009
August 2009
September 2009
October 2009
- Building a Concrete Bath
- LED Lighting Comparison
- Thinking about Programming Languages
- How To Be A Consultant
- Lucid Programming Dojo
- Exim4 + ClamAV + SpamAssassin
- Secure login using AJAX
- Ramaze And Rack
- ActiveMerchant
- Concurrency And Immutability
- Floating Point Numbers
- Programming And Debugging
- Useful jQuery Plugins
- Loading Anonymous Ruby Classes
- 尺八 (Shakuhachi)
- Card Trick
- Object Oriented C
- Gemcutter
- Writing Clearly
- Richard Stallman In Christchurch
- Magnatune
- Client Side Graphing
- Zena CMS
November 2009
February 2010
March 2010
April 2010
May 2010
June 2010
July 2010
August 2010
September 2010
December 2010
January 2011
March 2011
May 2011
August 2011
September 2011
I've been working on cross-compiling various different libraries for iPhone development. It has been fairly difficult to say the least.
One issue I ran into was linking a static archive with an app. The static archive had several .o files which did not export a public API, but were still important due to static initialization - i.e. it looked a bit like this:
// MyImpl.cpp SomeClass _myInstance(...);
Because this class is instantiated, it caused some functionality elsewhere in the app. The purpose of this is to de-couple implementations for specific behaviours from the actual interface - in this case, an image loader that supports several different formats. The benefit of this is that client code doesn't need to know the exact format of the data it is processing, only that it meets a specific abstract interface (in this case IPixelBuffer).
The issue with compiling this to an archive, is that during the link phase, code like this was not getting included in the end result. This is because there was no need for any symbols (obviously) within this .o file within the archive, so it was left out entirely.
There are a number of different solutions to this problem, but on Mac OS X, a quick easy option is the -all_load flag which is passed to ld. From the ld man page:
- -all_load
- Loads all members of static archive libraries.
This can be added into an Xcode project from the build options as Other Linker Flags.
Comments
Please note, you can leave a comment that uses (limited) XHTML and Textile syntax.