Hi,
I'm creating a static library for use in iPhone applications. It contains a number of source files which export no symbols, all they do is instantiate a static instance of a class which then runs some code in its constructor that registers various things with a central manager class elsewhere. This all works fine when the code is built as part of a standard iPhone application, but when it is separated into a static library these files don't make it into the final application binary and so the constructors for the private class instances they contain don't get run, and this causes problems. I've turned off every build option to do with dead stripping and so on for both the static library build and the final application build.
I ran into this issue on the Metrowerks compiler a while ago, however in that instance it was occurring even when the code was built into a single application without any intermediate libraries. The solution was quite straightforward: just use __declspec(force_export)
on the private class instances and all is well.
Is there any equivalent for GCC/iPhone? I'm using Xcode 3.1.4 with GCC 4.2 and targeting iPhone OS 3.1. Alternatively is there some way to tell the application to link in every object file in the static library regardless of whether or not it's explicitly referenced? I've confirmed using ar
that the full set of object files are making it into the static library.
Thanks in advance.