I’m building few command-line utilities in Xcode (plain C, no Cocoa). I want all of them to use my customized version of libpng, and I want to save space by sharing one copy of the library among all executables (I don’t mind re-distributing .dylib with them).
Do I need to do some magic to get libpng export symbols?
Does ‘Link Binary With Libraries’ build phase link statically?
Apple’s docs mention loading of libraries at run time with dlopen, but how I can make Xcode create executable without complaining about missing symbols?
I think I’ve figured it out:
-
libpng wasn’t linking properly, because I’ve built 32/64-bit executables and 32-bit library. Build settings of the library and executables must match.
-
libpng’s config.h needs to have tons of defines like
#define FEATURE_XXX_SUPPORTED -
‘Link Binary With Libraries’ build phase handles dynamic libraries just fine, and
DYLD_FALLBACK_LIBRARY_PATHenvironmental variable is neccessary for loading.dylibs from application bundle.
You probably need to ensure that the dynamic library you build has an exported symbols file that lists what should be exported from the library. It’s just a flat list of the symbols, one per line, to export.
Also, when your dynamic library is built, it gets an install name embedded within it which is, by default, the path at which it is built. Subsequently anything that links against it will look for it at the specified path first and only afterwards search a (small) set of default paths described under
DYLD_FALLBACK_LIBRARY_PATHin thedyld(1)man page.If you’re going to put this library next to your executables, you should adjust its install name to reference that. Just doing a Google search for ‘install name’ should turn up a ton of information on doing that.