XCode 4添加dylib [英] XCode 4 adding dylib

查看:240
本文介绍了XCode 4添加dylib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建,然后将dylib添加到项目。
我通过使用Cocoa-Library模板并将类型设置为动态(不确定应该是动态还是静态)来创建它。然后我创建了一个简单的obj-c类Test,并在其中打印出一些控制台的方法。

I am trying to create and then add the dylib to a project. I created it by using the "Cocoa-Library" template and setting the type to "Dynamic" (not sure if it should be dynamic or static...). Then I created a simple obj-c class called Test and wrote a method in it that prints out something to console.

我编译并使用生成的.dylib文件和put它在另一个项目。

I compiled and used the generated .dylib file and put it in another project. Now whenever I try to use it, I get this message on runtime"

dyld: Library not loaded: /usr/local/lib/TESTLib.dylib
  Referenced from: /Users/***/Library/Developer/Xcode/DerivedData/TestingDYLIB-axmoocnxbwznoyerfogosumqufxc/Build/Products/Debug/TestingDYLIB.app/Contents/MacOS/TestingDYLIB
  Reason: image not found

我还创建了一个复制文件阶段,并将目标设置为框架。我仍然得到相同的错误。
我做错了什么谢谢。

I also created a Copy File phase and set the destination to "Frameworks". I still get the same error. What am I doing wrong? Thanks.

推荐答案

问题是使用dylib的应用程序在运行时找不到它,当一个应用程序构建使用动态库,它将dylib的install_name复制到输出二进制文件中。

The issue is that the application which uses the dylib cannot find it at runtime. When an application is built that uses a dynamic library, it copies the install_name of the dylib into the output binary.

创建一个复制文件阶段,并将dylib复制到Frameworks子目录应用程序的包是正确的做。

Creating a copy files phase and copying the dylib to the Frameworks subdirectory of the app's bundle is the right thing do do.

但是,您需要执行一个额外的步骤。您需要使用适合于捆绑应用程序的install_name来编译动态库。默认情况下,将使用install_name为/ usr / local / lib创建动态库。应用程式找不到您的媒体库,因为它不存在。即使你把库放在那里,你的用户肯定不会有,所以这将是错误的解决方案。

However, you need to do an additional step. You need to compile the dynamic library with an install_name appropriate for a bundle app. By default, a dynamic library is created with an install_name of /usr/local/lib. The app can't find your library there because it doesn't exist. Even if you put the library there, your users certainly won't have it, so that would be the wrong solution.

正确的解决方案是捆绑库与应用程序。要设置动态库的安装名称,请进入动态库项目,并将动态库安装名称选项设置为:@executable_path /../ Frameworks / libmydynamiclibrary.dylib

The right solution is bundling the library with the app. To set the install name for the dynamic library, go into the dynamic library project and set the "Dynamic Library Install Name" option to: @executable_path/../Frameworks/libmydynamiclibrary.dylib

这篇关于XCode 4添加dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆