I have a Cocoa Touch framework which consists of 99.9% pure C code with just a tiny layer of Objective C on top of it. The framework should just export a single symbol named mytestsymbol
. To do this, I create an exported symbols file that contains just this line:
_mytestsymbol
I then tell the linker to use this file by adding it to the "Exported Symbols File" entry in "Build Settings/Linking" in Xcode.
In terms of C code, mytestsymbol
looks like this:
void mytestsymbol(void)
{
start_the_whole_shebang();
}
However, when building the framework and examining the executable's contents using a hex editor I can see that pretty much all global symbols defined in my C sources are still there but I don't want to expose those!
When checking the stripping options of the Cocoa Touch framework in Xcode I can see that by default this is just set to "Debugging symbols" whereas when building apps it is set to "All symbols" by default. So I changed the "Strip style" mode to "All symbols" for my framework and tried to archive it.
However, that doesn't work either. Now strip
returns the following error when archiving the project:
Symbols referenced by indirect symbol table entries that can't be stripped in: ...
Then a list of symbols follows. Those are all symbols my framework imports from other frameworks, e.g. stuff from the C runtime like printf
, fopen
, etc but also stuff from Apple frameworks like CFBundleCopyBundleURL
and so on.
So I think I get this error because strip
tries to strip those symbols but this is of course forbidden because those are needed by my framework.
So how can I tell Xcode to strip only the global symbols defined by my framework (except mytestsymbol
) and not any other imports from other frameworks? Currently, it doesn't seem possible to set the stripping style to "All symbols" for Cocoa Touch Frameworks at all. Whenever this is set to "All symbols", strip
(which is invoked by Xcode) always returns the following error:
Symbols referenced by indirect symbol table entries that can't be stripped in: ...
Note that I'm talking about stripping global C symbols only. I know that Objective C can't be stripped like C but that's fine with me. I'm really only concerned about the C symbols. I want all C globals to be stripped except the symbol named mytestsymbol
.
Any ideas?
To answer my own question: It's impossible to use the strip style "All Symbols" with Cocoa Touch Frameworks because relocatable dynamic libraries (which Cocoa Touch Frameworks basically are) which reference external symbols like
printf
need an indirect symbol table which won't be there if "Strip Style" is set to "All Symbols".Thus, "Strip Style" should simply be set to "Non-Global Symbols". The naming is a bit confusing here because "Non-Global Symbols" sounds as if
strip
didn't strip symbols likemytestsymbol
in the code above (because it is a global symbol) but in fact it does strip it. So just using the "Non-Global Symbols" strip style works perfectly.