dyld:库未加载 - 当应用程序从命令行运行时
当我从命令行运行 iPhone 应用程序时,向项目添加框架时遇到一些困难。 我的最终目标是从自动构建过程运行应用程序测试。
当我从 xCode 运行我的应用程序时:
我向我的目标添加“复制文件”构建阶段,一切顺利。 副本设置为 $(BUILT_PRODUCTS_DIR) 作为“绝对路径”
当我从终端运行我的应用程序(使用 iphonesim 项目)时,我收到此错误:
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
我不明白的是,复制构建阶段只是将框架文件复制到相同的位置目录作为应用程序。
当我从命令行运行应用程序时,框架文件已经位于同一目录中。有谁知道为什么它不起作用?
我还尝试在以下目录中添加 OCMock.framework (没有成功):
/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
提前致谢, 文森特.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚在 Lion 上的 Xcode 4.2 (4D199) 中遇到了同样的错误。我将 OCMock.framework 文件夹拖放到我的项目中,并选中“复制文件”复选框。我看到了上面的答案,并意识到我忽略了添加“复制文件”构建阶段来将框架移动到位。我添加了一个并在编译文件构建阶段之后将其拖动,并尝试再次运行我的测试。直到我将“复制文件”阶段中的目标更改为“产品目录”后,我才能使其正常工作。使用“框架”或“共享框架”不起作用。
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.
iPhone 不支持传统的 Mac OS X 框架。虽然 iPhone 确实使用以“.framework”结尾的文件夹,但这些文件夹的结构与典型的 Mac OS X 框架不同。最值得注意的是,iPhone 框架只允许使用静态库,而典型的 Mac OS X 框架是动态加载的。该消息来自 dyld 表明您正在使用共享库;但是,针对 iPhone 的应用程序只能静态链接。
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 作为框架进行分发,iPhone 不允许您构建自己的任意框架(有充分的理由在只有 128MB RAM 并且没有交换区的设备上执行此操作)。
我在网络上很多地方看到的解决方案是将 OCMock.framework 放在 /Library/Frameworks 或标准框架搜索路径中的任何其他位置。这不是一个很好的解决方案:您的构建系统现在取决于特定机器的状态。不好。
另一种选择是将 OCMock 源添加到您的单元测试目标中。这可以工作,但没有必要,因为您的测试永远不会在 iPhone 上运行,2 那么为什么还要为 ARM 构建它们呢?为 iPhone 模拟器构建的可执行文件(Mac OS X 二进制文件)可以很好地链接到动态库。我们可以利用这一点来发挥我们的优势。
以下是我认为让 OCMock 处理 iPhone 项目的最佳方法:
首先,将 OCMock.framework 添加到您的项目中。确保将其添加到您的单元测试目标中,而不是您的应用程序中。
接下来,将复制文件阶段添加到您的单元测试目标。像这样设置:
Destination :Absolute Path
完整路径:$(BUILT_PRODUCTS_DIR)
现在,将 OCMock.framework 拖到新的复制文件阶段,将其添加到要复制的文件列表中。
最后,将“复制文件”阶段(我将其重命名为“复制 OCMock”)拖动到“编译源”和“链接二进制文件与库”阶段之间。
就是这样!运行(我所说的运行是指构建)你的测试,一切都应该正常工作。
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.