I'm using the apple gcc to compile a dylib that I'm going to redistribute. For various reasons I'm using some libraries, let's say libz
to keep it simple.
Since this library is not typically found on a Mac system I wish to static link in used symbols into the dylib by passing the path to the .a-file
to simplify deployment.
Now, the linker links in all symbols from the lib into the resulting dylib although I only reference a subset. On linux I've never encountered this problem, the linker happily discards all unreferenced symbols and creates a very slim executable, so it should be possible. The dylib file I have now is ~10 times larger than it should.
I've tried fiddle around with the -dead_code linker flag, but to no avail. Perhaps I just don't understand it?
Does anyone know the solution to this?
Try
-Wl,--gc-sections
.As regards
-dead_strip
(what you probably meant by-dead_code
):and:
Hope this helps.
All content in this answer was located within the first few Google search results for "apple ld static link unused symbols". :)