Dyld: library not loaded. When the application starts from the command line

I am having some difficulty adding a frame to my project when I launch an iPhone application from the command line. My ultimate goal is to run application tests from an automated build process.

When I launch my application from xCode:

I add the “Copy File” build phase to my target, and everything is going well. The copy is set to $ (BUILT_PRODUCTS_DIR) as "Absolute path"

When I launch my application from the terminal (using the iphonesim project), I get this error:

dyld: Library not loaded: @rpath/OCMock.framework/Versions/A/OCMock UIKitApplication:indemnisation[0xb894][26380] Referenced from: /Users/Admin/Library/Application Support/iPhone Simulator/User/Applications/CD5729B5-A674-49B2-91F6-AD398094B6F8/indemINT.app/indemINT 

What I don’t understand is that the copy phase is copying the framework files in the same directory as the application.

When I launch the application from the command line, the framework files are already in the same directory. Does anyone know why this is not working?

I also tried adding OCMock.framework to the following directories (without success):

  /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library /Library/Frameworks /Users/Admin/Library/Application Support/iPhone Simulator/User/Applications/CD5729B5-A674-49B2-91F6-AD398094B6F8 

Thanks in advance, Vincent.

+6
iphone dyld
source share
3 answers

I had the same exact error in Xcode 4.2 (4D199) on Lion. I dragged / dropped the OCMock.framework folder into my project and checked the "Copy files" checkbox. I saw the above answers and realized that I forgot to add the “Copy Files” build phase to move the structure into place. I added one and dragged it right after the build phase of the compilation files and tried again to run my tests. I could not get it to work until I changed the destination in the "Copy Files" phase to the "Product Directory". Using Frames or General Frames does not work.

+8
source share

iPhone does not support traditional Mac OS X environments. While iPhone uses folders that end in ".framework", these folders are structured differently from regular Mac OS X frames. First of all, only static libraries are allowed for iPhone frameworks. whereas typical Mac OS X environments load dynamically. That the message comes from dyld indicates that you are using shared libary; however, iPhone-targeted applications can only be connected statically.

+2
source share

OCMock is distributed as a basis, and the iPhone does not allow you to create your own custom frameworks (there are good reasons to do this on a device with 128 MB of RAM and without sharing).

The solution that I see in many places on the Internet is to put OCMock.framework in / Library / Framework or elsewhere in the standard wireframe search paths. This is not a good solution: your build system now depends on the state of your particular machine. Not good.

Another option is to add the source for OCMock to your unit test target object. This will work, but is not necessary, since your tests will never run on the iPhone 2, so why bother them for ARM? The executables created for the iPhone simulator, which are binary files in Mac OS X, can work well with dynamic libraries. We can use this to our advantage.

The following is what I consider the best way to get OCMock working with iPhone projects:

First add OCMock.framework to your project. Make sure to add it to the Unit Tests target program, not your application.

Then add the “Copy Files” phase to the “Test Units” target. Set it up like this:

Destination: Absolute Path Full Path: $ (BUILT_PRODUCTS_DIR)

Now drag OCMock.framework onto the new Copy Files phase to add it to the list of files you want to copy.

Finally, drag the “Copy Files” phase, which I renamed to “Copy OCMock,” between the “Compile Sources” and “Linking Binary Files to Libraries” steps.

Here it is! Run (and run, I mean build) your tests, and everything should work correctly.

0
source share

All Articles