Search code examples
xcodecocoastatic-linking

Do I need to link libs that dependencies link?


I'm trying to write a simple game engine for iOS in Objective C and C++ using Xcode.

I've made a game project and a game engine project. The latter is added to the former as a subproject. The engine is also added as a target dependency and as a binary to be linked in the game project.

My engine uses CADisplayLink so I add QuartzCore.framework in the engine project's "Link binary with libraries list" (found in Build phases).

Now, when I try to build my game project (the project with the subproject), I get this error:

Undefined symbols for architecture i386: "_OBJC_CLASS_$_CADisplayLink", referenced from: objc-class-ref in libVoya-iOS.a

This error only happens when building from the game project - doing it from the engine project works fine. If I add QuartzCore.framework to the game project building works fine.

Can it really be true I have to specifically require frameworks that one of my target dependencies already have required? In this case: My engine (sub project) already links QuartzCore - is it really necessary to also do this in the projects using this engine? It feels like double work for no reason.

Or perhaps I've just completely misunderstood something? :)


Solution

  • I've now found the answer to my question and I'd like to share it.

    Static libraries are nothing more than a grouping of the compiled versions of the library's source files. They do not include any libraries they themselves might depend on.

    Fusing all dependencies together happens only when you build the actual executable in the very end. For this reason, your application should indeed link against your dependencies' dependencies.

    As for the example in my question, that means that my game should link QuartzCore while my game engine should not (even though it is my GameEngine who is using it).

    Learn more here: