使用私有dylib / framework构建Cocoa应用程序包

时间:2022-09-25 12:28:39

I use xcode 4 to build a cocoa application with a private dylib/framework.

我使用xcode 4来构建一个带有私有dylib / framework的cocoa应用程序。

In my development Mac, I put the dylib in the /usr/local/lib directory, and drag it into the project.

在我的开发Mac中,我将dylib放在/ usr / local / lib目录中,并将其拖到项目中。

The app is compiled and runs perfect on my computer.

该应用程序已编译并在我的计算机上运行完美。

To distribute this app to the other Mac, I create a copy Files building phase, and say "copy that dylib to Frameworks directory".

要将此应用程序分发到其他Mac,我创建一个文件构建阶段的副本,并说“将该dylib复制到Frameworks目录”。

The application is built successfully, and I indeed see the dylib is copied to the Frameworks directory in the app bundle.

应用程序构建成功,我确实看到dylib被复制到应用程序包中的Frameworks目录。

The problem is when I run this app in another regular Mac, which does not have this dylib installed. I get an error saying:

问题是当我在另一台没有安装此dylib的常规Mac上运行此应用程序时。我收到一个错误说:

dyld: Library not loaded: /usr/local/lib/mylib.dylib

1 个解决方案

#1


9  

The issue comes from the fact that you copy the framework into the app bundle, so it is available at a location like:

问题来自于您将框架复制到应用程序包中,因此可以在以下位置使用:

 <you_app_path>/Contents/Frameworks

but you try to load it from /usr/local/lib where it is not available on you deployment machine. From Apple Framework Programming Guide:

但是您尝试从/ usr / local / lib加载它,在部署机器上它不可用。从Apple Framework编程指南:

To embed a framework in an application, there are several steps you must take:

要在应用程序中嵌入框架,必须采取以下几个步骤:

You must configure the build phases of your application target to put the framework in the correct location.

您必须配置应用程序目标的构建阶段,以将框架放在正确的位置。

You must configure the framework target’s installation directory, which tells the framework where it will live.

您必须配置框架目标的安装目录,该目录告诉框架它将存在的位置。

You must configure the application target so that it references the framework in its installation directory.

您必须配置应用程序目标,以便它引用其安装目录中的框架。

Now, you say that the build phase is ok; I assume also that you sent the application target build setting correctly. What is left is configuring the framework target’s installation directory.

现在,你说构建阶段是好的;我还假设您正确发送了应用程序目标构建设置。剩下的是配置框架目标的安装目录。

If you did not build the framework yourself, you should be able to fix this by changing the framework install path so that it is defined relative to the loader (your app), to something like: @loader_path/../Frameworks/ (or @executable_path/../Frameworks). You can do that by means of install_name_tool.

如果您没有自己构建框架,您应该能够通过更改框架安装路径来修复此问题,以便相对于加载器(您的应用程序)定义它,如下所示:@loader_path /../ Frameworks /(或@executable_path /../框架)。您可以通过install_name_tool来实现。

If you are compiling on your own the private framework, you can define its install location in Xcode build settings.

如果您自己编译私有框架,则可以在Xcode构建设置中定义其安装位置。

#1


9  

The issue comes from the fact that you copy the framework into the app bundle, so it is available at a location like:

问题来自于您将框架复制到应用程序包中,因此可以在以下位置使用:

 <you_app_path>/Contents/Frameworks

but you try to load it from /usr/local/lib where it is not available on you deployment machine. From Apple Framework Programming Guide:

但是您尝试从/ usr / local / lib加载它,在部署机器上它不可用。从Apple Framework编程指南:

To embed a framework in an application, there are several steps you must take:

要在应用程序中嵌入框架,必须采取以下几个步骤:

You must configure the build phases of your application target to put the framework in the correct location.

您必须配置应用程序目标的构建阶段,以将框架放在正确的位置。

You must configure the framework target’s installation directory, which tells the framework where it will live.

您必须配置框架目标的安装目录,该目录告诉框架它将存在的位置。

You must configure the application target so that it references the framework in its installation directory.

您必须配置应用程序目标,以便它引用其安装目录中的框架。

Now, you say that the build phase is ok; I assume also that you sent the application target build setting correctly. What is left is configuring the framework target’s installation directory.

现在,你说构建阶段是好的;我还假设您正确发送了应用程序目标构建设置。剩下的是配置框架目标的安装目录。

If you did not build the framework yourself, you should be able to fix this by changing the framework install path so that it is defined relative to the loader (your app), to something like: @loader_path/../Frameworks/ (or @executable_path/../Frameworks). You can do that by means of install_name_tool.

如果您没有自己构建框架,您应该能够通过更改框架安装路径来修复此问题,以便相对于加载器(您的应用程序)定义它,如下所示:@loader_path /../ Frameworks /(或@executable_path /../框架)。您可以通过install_name_tool来实现。

If you are compiling on your own the private framework, you can define its install location in Xcode build settings.

如果您自己编译私有框架,则可以在Xcode构建设置中定义其安装位置。