3

我正在尝试让 dylib 在我的 OSX 项目中工作。

我一直在阅读一些示例,特别是这个: Xcode 4 added dylib

但我仍然无法让它工作。

以下是我执行的步骤:

  1. 将 testing.1.dylib 复制到我的 Xcode 项目文件夹中。
  2. sudo install_name_tool -id @executable_path/../Frameworks/testing.1.dylib testing.1.dylib
  3. 冉:otool -L testing.1.dylib并收到以下信息:

    testing.1.dylib:
    @executable_path/../Frameworks/testing.1.dylib(兼容版本 2.0.0,当前版本 2.0.0)
    /usr/lib/libSystem.B.dylib(兼容版本 1.0.0,当前版本 159.1.0)

  4. testing.1.dylib作为框架添加到项目中。(使用带有库选项的链接包)。

  5. 此时,当我编译 testing1.dylib 时并没有像我预期的那样被复制到 .App/Framework 中,所以我手动创建了 Framework 路径并将 testing.1.dylib 复制到它: a) mkdir -p testing.app /Contents/Frameworks b) cp testing.1.dylib testing.app/Contents/Frameworks
  6. 在 Xcode 中,我Runtime Search Paths将 Target 和 Project 都更新为:@executable_path/../Frameworks。

现在我将 testing.app 复制到一个单独的新安装的机器上并尝试运行它。我收到以下错误:

dyld:库未加载:/user/local/lib/testing1.dylib 引用自:/Users/me/testing.app/MacOS/./testing 原因:找不到图像

我错过了什么?

注意:运行 install_name_tool 时,我需要使用 sudo 否则会出现以下错误:

install_name_tool:无法打开输入文件:testing.1.dylib 用于写入(权限被拒绝) install_name_tool:无法在文件中偏移:0:testing.1.dylib 用于写入(错误的文件描述符) install_name_tool:不能在文件中写入新标头:testing.1.dylib(错误文件描述符) install_name_tool:无法关闭写入输入文件:testing.1.dylib(错误文件描述符)

4

2 回答 2

1

You shouldn't need to copy the library into the project.

You shouldn't need to use sudo to change the install name of a file you own. Do you not own the library file? Perhaps you did a "sudo make install" on some third-party project? Just don't install it and link to the one in the build directory. If you're building this library, then you should set its install name when it's built using command-line options to the link command.

It is expected that adding a library to a target causes it to be linked but doesn't automatically cause it to be copied. You can create a Copy Files build phase and add the library to that, too.

You don't need to set Runpath Search Paths unless you used an @rpath-based install name.

I suspect that Xcode is actually linking against the library that you copied from in step 1, rather than the copy you made and whose install name you then modified. What does the actual link command from the build transcript say? From where did you copy the library in step 1? If it was from /usr/lib or /usr/local/lib, then Xcode is probably linking against that.

于 2012-04-28T14:04:43.700 回答
1

在您引用的“XCode 4 添加 dylib”问题中,答案似乎是设置“复制文件”构建阶段。这非常简单,因为您的 dylib 中已经有了 write 可执行路径。现在只需转到您的目标设置 > 构建阶段 > 添加构建阶段 > 复制文件。然后将 dylib 从 Navigator 侧边栏拖到文件中,并将目标设置为 Frameworks。

这应该将 dylib 捆绑到您的应用程序包内容中,并且 dylib 中的可执行路径应该指向正确的内容。

于 2013-05-27T22:56:53.420 回答