You are not Banksy

Tags: , ,

XCode dependency hell

Dear Lazyweb, how do I add dependencies to Xcode without also adding link rules?

Alternately, how do I add platform-specific library linking without also losing dependencies on those libraries?

My project builds a static library, and a bunch of bundles, for all platforms.

The complicated part is, the bundles link against that library on MacOS but not on iOS.

The only way I've found to accomplish that is to remove MyLib.a from the "Link Binary With Libraries" field and instead add it explicitly to the "Other Linker Flags" field like this:

  • Other Linker Flags:
    • Debug
      • Any Mac OS X SDK:     -lMyLib ...
      • Any iOS Simulator SDK:     -undefined dynamic_lookup ...
      • Any iOS SDK:     -undefined dynamic_lookup ...
    • Release
      • ...same...

This is because you can't add an SDK-conditional setting like that on the "Link Binary With Libraries" field in the UI. It's all or nothing.

I still have "MyLib" in the "Target Dependencies" field, and when I build the bundle, it does re-build the library first as needed...

However, if a source file linked into the library was changed but a source file linked into the bundle was not, it does not re-link the bundle against the library on MacOS! It leaves it out-of-date with the wrong code, even though the build log shows a "Link" phase running "clang" to link it. Apparently that's a lie.

I even tried adding a "Shell Script" phase that runs before the "Link" phase and manually checks the dates on the files and deletes the output files that are out of date, but even that didn't make the later link phase re-link. Apparently "the target file doesn't exist" is not enough of a whack upside the head of that lying link phase to tell it that it actually has to link. With this hack, I just end up without a runnable program and have to hit "Build" again, which I guess is better than having the wrong program...

So how do I tell Xcode, "when library A is newer than binary B, binary B needs to be re-linked" -- without also telling it, "link binary B against file A on every platform"?

Tags: , , ,