English 中文(简体)
dyld: Library not loaded - When app run from the command line
原标题:
  • 时间:2010-03-18 17:35:48
  •  标签:
  • iphone
  • dyld

I face some difficulties when adding a framework to my project 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.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签