I'm splitting a largish iOS app into a few frameworks, and I'm facing the following problem:
How do I properly include a custom Cocoa Touch framework project into an iOS app project, so that everything links properly?
- I have created a project framework, with all the necessary code inside.
- To test things out, I've created a sample workspace, and added the framework project to it.
- Next, I've created a sample iOS app project, with a few lines of code using the framework, and added the project to the workspace as well.
Now, I get to the linking part.
First attempt:
Open the app target settings in Xcode, select the
Infopane, and add the framework in theLinked Frameworks and Librariessection.To make things nice, I also select the newly added framework in the app project, and change it's
LocationfromRelative to GrouptoRelative to Build Products. Beneath the location shows as../Debug-iphonesimulator/MyFramework.frameworkThe current scheme is
<Simulator, Debug>, I hitRun, and everything works as it should - the app logs that it's using the framework fine.Now, I clean the build folder, and change the scheme to
<Simulator, Release>.Next, I hit
Run, the projects start building, and then app linking fails:
Undefined symbols for architecture x86_64: <a function from the framework> referenced from: <a file in the app>.
Upon inspecting the build folder, I can see that the framework was built properly, resides in .../Build/Products/Release-iphonesimulator/..., and is a fat binary with both i386 and x86_64 inside.
How should I proceed to properly link the framework, so that it works in any configuration (Debug, Release), and on both the simulator and, of course, devices?
To clarify, I intend to develop both the framework(s), and the app simultaneously, so a solution like e.g. CocoaPods does it, by pre-building fat frameworks once, seems not very practical (unless I'm missing something, due to lack of sufficient experience with CocoaPods).
Below is the failing Link phase output:
Ld /Users/me/Library/Developer/Xcode/DerivedData/MyWorkspace-ahzqvfgoxbedpudjdhtqudgqzwba/Build/Intermediates/MyApp.build/Release-iphonesimulator/MyApp.build/Objects-normal/x86_64/MyApp normal x86_64
cd /some/where/here/lives/the/workspace
export IPHONEOS_DEPLOYMENT_TARGET=9.3
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk
-L/Users/me/Library/Developer/Xcode/DerivedData/MyWorkspace-ahzqvfgoxbedpudjdhtqudgqzwba/Build/Products/Release-iphonesimulator
-F/Users/me/Library/Developer/Xcode/DerivedData/MyWorkspace-ahzqvfgoxbedpudjdhtqudgqzwba/Build/Products/Release-iphonesimulator
-filelist /Users/me/Library/Developer/Xcode/DerivedData/MyWorkspace-ahzqvfgoxbedpudjdhtqudgqzwba/Build/Intermediates/MyApp.build/Release-iphonesimulator/MyApp.build/Objects-normal/x86_64/MyApp.LinkFileList
-Xlinker
-rpath
-Xlinker @executable_path/Frameworks
-mios-simulator-version-min=9.3
-Xlinker
-objc_abi_version
-Xlinker 2
-fobjc-arc
-fobjc-link-runtime
-stdlib=libc++
-framework MyFramework
-Xlinker
-dependency_info
-Xlinker /Users/me/Library/Developer/Xcode/DerivedData/MyWorkspace-ahzqvfgoxbedpudjdhtqudgqzwba/Build/Intermediates/MyApp.build/Release-iphonesimulator/MyApp.build/Objects-normal/x86_64/MyApp_dependency_info.dat
-o /Users/me/Library/Developer/Xcode/DerivedData/MyWorkspace-ahzqvfgoxbedpudjdhtqudgqzwba/Build/Intermediates/MyApp.build/Release-iphonesimulator/MyApp.build/Objects-normal/x86_64/MyApp
Undefined symbols for architecture x86_64:
"SomeFancyFuncFromTheFramework()", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o

MyApp_dependency_info.datfile (from the last-Xlinkerarguments) contains references to bothMyFramework.framework/MyFramework.tbdandMyFramework.framework/MyFramework, both inside.../Build/Products/Release-iphonesimulator/, from what I could tell (and FWIW).