Note that there are some explanatory texts on larger screens.

plurals
  1. POXcode: Linking brand new framework to brand new app fails with "image not found"
    primarykey
    data
    text
    <p>I'm totally new to Xcode and Objective-C, but an experienced (web) programmer otherwise. I want to create an app that includes a self-made framework.</p> <p>Now I've read quite a bit on it, I think I've got a reasonable grasp of how OS X resolves dependencies at runtime, and the role of @rpath, @executable_path and @loader_path.</p> <p>I did the following to create the framework:</p> <ol> <li>Create new Cocoa Framework named Test.</li> <li>Set installation directory to "@rpath".</li> <li>Add "Test.h" to public headers.</li> <li>Click run.</li> <li>Right click on Test.framework under "Products", choose Show in Finder. It's a directory called "Test.framework" in the "Debug" directory of the project. It seems to have reasonable contents (Versions/A directory and symlinks to "Headers", "Resources" and the "Test" binary)</li> </ol> <p>I did the following to create the app:</p> <ol> <li>Create new Cocoa app named "TestApp".</li> <li>Add test framework to project. Choose "Add files to project". Select "Test.framework" directory from "Release" directory of the Test framework project. "Copy items into destination group's folder" is checked Leave "Create groups for any added folders." on.</li> <li>Make sure framework files are copied to application bundle. Choose "Add Build Phase" -> "Add Copy Files" Drag Test.framework folder (or group?) from the sidebar into the Copy Files area.</li> <li>Add an extra "framework search path" named "@executable_path/../Frameworks"</li> </ol> <p>When I choose run, I get the following warning during build:</p> <blockquote> <p>Build target TestApp</p> <p>Ld /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp normal x86_64 cd /Users/meryn/Work/test-app/TestApp setenv MACOSX_DEPLOYMENT_TARGET 10.8 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug -F/Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug -F/Users/meryn/Work/test-app/TestApp "-F@executable_path/../Frameworks" -filelist /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Intermediates/TestApp.build/Debug/TestApp.build/Objects-normal/x86_64/TestApp.LinkFileList -mmacosx-version-min=10.8 -fobjc-arc -fobjc-link-runtime -framework Cocoa -framework Test -o /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp</p> <p>ld: warning: directory not found for option '-F@executable_path/../Frameworks'</p> </blockquote> <p>I can imagine this warning is to be expected, as Ld may not know about "@executable_path" at all. Is this correct?</p> <p>Subsequently, running the app fails with:</p> <blockquote> <p>dyld: Library not loaded: @rpath/Test.framework/Versions/A/Test Referenced from: /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app/Contents/MacOS/TestApp Reason: image not found</p> </blockquote> <p>The peculiar thing is that the TestApp.app package does contain a Frameworks directory, with the Test.framework directory inside. Given what I understand about how OS X would search for dependencies, I think the search path that I added should resolve fine.</p> <p>This is on XCode 4.6, OS X 10.8.</p> <p><code>otool -L TestApp</code> gives</p> <blockquote> <p>TestApp:</p> <p>/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)</p> <p>@rpath/Test.framework/Versions/A/Test (compatibility version 1.0.0, current version 1.0.0)</p> <p>/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)</p> <p>/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)</p> <p>/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)</p> <p>/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.33.0)</p> </blockquote> <p>Is it ok to see "@rpath" unexpanded here?</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COSo you DID add the framework to the copy-phase, so it exists inside the bundle, at runtime, which is inside your target app, which is in the derived data folder? I suspect something is wrong with the framework file you've added. Try deleting it and adding it again to the project.
      singulars
    2. COWell, inside /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app (the thing that gets built) I have Contents/Frameworks/Test.framework , which includes a symlink to a "Test" binary file, amongst other things. I'm not sure what you mean by the "bundle". Is the bundle equivalent to the app "folder"? In Finder it says "Show Package Contents" so I figured it was called a package. I'll try re-adding anyway. Who knows. :)
      singulars
    3. CONo joy. Are there any other things I could look into? I don't mind learning a bit about OS X (that is, its development infrastructure) in the meantime. For example, is there a way to check if "image not found" simply means "cannot find the file" or that the file is corrupted or so? Can I run dyld manually, applying it to the app "package" (or the app binary inside it) that got build?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload