I’m having problems with an Xcode target that simply takes a static library (.a file) built by another target, and relinks it into a .dylib. Sometimes the dylib comes out empty — a tiny file with no symbols. I’ve gotten to where this only happens sporadically, but it’s still a pain.
Context: I’ve got a library that’s built as part of my (fairly complex) project. Some targets want to link with it as a static library, and others want it as a dylib, so I need two targets that build the library as either type. To avoid having to duplicate a bunch of info like the list of source files and the compiler settings, I made the dylib-generating target dependent on the static-lib target, and it just links with the static lib. Schematically, the two targets are like:
StaticFoo:
x.c, y.c, z.m ⟶ foo.a
DynamicFoo: foo.a ⟶ foo.dylib [dependency on StaticFoo]
When I initially set this up, foo.dylib didn't even get created at all. I figured out that I had to add a single source file to the target, even if all it has is just a no-op static function. I assume this is an edge case in the Xcode build system, where if there are no source files at all it doesn’t think there’s anything to do so it doesn’t run the linker.
Now it mostly works, but I find that after switching schemes in Xcode the build will fail because foo.dylib gets rebuilt and comes out empty. foo.a is fine, but foo.dylib is a tiny stub file with no symbols in it. This then of course causes link errors in the targets that link with foo.dylib.
Any idea what’s wrong in the DynamicFoo target? I’ve added the “-all_load” linker flag, thinking that maybe the entire .a file was being dead-stripped, but that didn’t change anything.