开发者

dyld: Library not loaded - When app run from the command line

开发者 https://www.devze.com 2022-12-23 03:37 出处:网络
I face some difficulties when adding a framework to my pr开发者_StackOverflowoject when i run an iPhone app from the command line.

I face some difficulties when adding a framework to my pr开发者_StackOverflowoject when i run an iPhone app from the command line. My final goal is to run applications tests from an automated build process.

When i run my app from xCode :

I add a "Copy File" build phase to my target and everything goes fine. The copy is set to $(BUILT_PRODUCTS_DIR) as "Absolute path"

When i run my app from the terminal (using 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 dont understand is that the copy build phase just copies the framework files in the same directory as the app.

When i run the app from the command line the framework files are already in the same directory. Does anyone knows why it doesn't work ?

I've also tried to add the OCMock.framework in 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.


I just had this same exact error in Xcode 4.2 (4D199) on Lion. I dragged/dropped the OCMock.framework folder into my project and selected the "copy files" checkbox. I saw the above answers and realized I neglected to add a "Copy Files" build phase to move the framework into place. I added one and dragged it right after the compile files build phase and tried to run my tests again. I couldn't get it to work until I had changed the destination in the "Copy Files" phase to the "Products Directory". Using "Frameworks" or "Shared Frameworks" did not work.


The iPhone does not support traditional Mac OS X frameworks. While the iPhone does use folders that end in ".framework", these folders are structured differently than typical Mac OS X frameworks. Most notably, iPhone frameworks are only permitted to use static libraries, while typical Mac OS X frameworks are dynamically loaded. That the message comes from dyld indicates that you are using a shared libary; however, applications targetting the iPhone may only be statically linked.


OCMock is distributed as a framework, and the iPhone does not allow you build your own arbitrary frameworks (there are good reasons to do this on a device with only 128MB of RAM and no swap).

The solution I see in a lot of places around the web is to put OCMock.framework in /Library/Frameworks or anywhere else in the standard framework search paths. This isn’t a very good solution: your build system is now dependent upon the state of your particular machine. Not good.

Another option would be to add the source for OCMock to your unit test target. This would work but is unnecessary, as your tests will never run on the iPhone,2 so why bother building them for ARM? Executables built for the iPhone simulator, being Mac OS X binaries, can link against dynamic libraries just fine. We can use this to our advantage.

What follows is what I believe is the best way to get OCMock working with iPhone projects:

First, add OCMock.framework to your project. Make sure that it’s being added to your Unit Tests target, not your application.

Next, add a Copy Files phase to your Unit Tests target. Set it up like so:

Destination :Absolute Path Full Path :$(BUILT_PRODUCTS_DIR)

Now, drag OCMock.framework onto your new Copy Files phase to add it to the list of files to be copied.

Finally, drag the Copy Files phase, which I renamed it to “Copy OCMock”, between the Compile Sources and Link Binary With Libraries phases.

That’s it! Run (and by run I mean build) your tests and everything should work correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消