Xcode: Binding new structure to new application failed with "image not found"

I am completely unfamiliar with Xcode and Objective-C, but an experienced (network) programmer otherwise. I want to create an application that includes a makeshift structure.

Now I read a little about it, I think I have a reasonable understanding of how OS X resolves runtime dependencies, as well as the roles of @rpath, @executable_path and @loader_path.

I created the following:

  • Create a new Cocoa Framework named Test.
  • Set the installation directory to "@rpath".
  • Add "Test.h" to the public headers.
  • Click "Run."
  • Right-click Test.framework in the Products section, select Show in Finder. This is a directory called "Test.framework" in the project's Debug directory. It seems to have reasonable content (Versions / Catalog and symbolic links to "Headings", "Resources" and "Test").

To create the application, I did the following:

  • Create a new Cocoa application called TestApp.
  • Add a test environment for the project. Select "Add Files to Project." Select the Test.framework directory in the Release directory of the Framework Test project. "Copy items to destination group folder" Leave "Create groups for any added folders." on the.
  • Make sure the frame files are copied to the application package. Choose Add Build Step β†’ Add Copy Files. Drag the Test.framework folder (or group?) From the sidebar to the Copy Files area.
  • Add an optional "wireframe search path" named "@executable_path /../ Frameworks"

When I select run, during build I get the following warning:

Create Target TestApp

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_ENGTOS MACHINE 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-ajwvknoonlixxqffa Debug -F / Users / meryn / Work / test-app / TestApp "-F @executable_path /../ Frameworks" file list / 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

ld: warning: directory not found for option '-F @executable_path /../ Frameworks'

I can imagine that this warning is to be expected, since Ld may not be aware of @executable_path at all. Is it correct?

Subsequently, when the application starts, it crashes:

dyld: library not loaded: @ rpath / Test.framework / Versions / A / Test Link from: /Users/meryn/Library/Developer/Xcode/DerivedData/TestApp-ajwvknoonliuqqfaqxacxrmapyfz/Build/Products/Debug/TestApp.app MacOS / TestApp Reason: Image not found

The peculiarity is that the TestApp.app package contains the Frameworks directory, inside which the Test.framework directory is located. Given that I understand how OS X will look for dependencies, I think the search path I added should be fixed.

This is on Xcode 4.6, OS X 10.8.

otool -L TestApp gives

TestApp:

/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)

@ rpath / Test.framework / Versions / A / Test (compatibility version 1.0.0, current version 1.0.0)

/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)

/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.33.0)

Is it possible to view "@rpath" here?

What am I doing wrong?

+4
source share
1 answer

Because the library identifier is set to @rpath -prefixed, the application connecting to the library must specify one or more -rpath parameters to indicate that dyld should replace the @rpath variable when searching for the library at run time. A typical value would be @loader_path/../Frameworks if you copy the framework to TestApp.app/Contents/Frameworks . You can set the value of the -rpath arguments using the LD_RUNPATH_SEARCH_PATHS (Path Search Paths) configuration parameter in Xcode in the TestApp target.

I can imagine that this warning is to be expected, since Ld may not be aware of @executable_path at all. Is it correct?

It is not useful to add @executable_path/../Frameworks in the Xcode framework search path. The wireframe search paths are the concept of the static linker of the static linker ( ld ), and the variables @executable_path are the concept of the dynamic runtime linker ( dyld ).

+9
source

All Articles