Xcode 4,dylib&install_name_tool [英] Xcode 4, dylib & install_name_tool

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

问题描述

我正在尝试在OSX项目中使用dylib.

I'm trying to get a dylib working in my OSX project.

我一直在阅读一些示例,特别是以下示例:Xcode 4 添加 dylib

Ive been reading a few samples, this one specifically: Xcode 4 adding dylib

但是我仍然无法使其正常工作.

But I still cannot get it to work.

这是我执行的步骤:

  1. 将testing.1.dylib复制到我的Xcode项目文件夹中.
  2. Ran sudo install_name_tool -id @executable_path/../Frameworks/testing.1.dylib testing.1.dylib
  3. Ran: 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)

testing.1.dylib:
@executable_path/../Frameworks/testing.1.dylib (compatibility version 2.0.0, current version 2.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

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

  • Added the testing.1.dylib as a framework to the project. (Using the link bundle with library option).

    现在,我将testing.app复制到另一台新安装的计算机上,然后尝试运行它.我收到以下错误:

    Now I copy the testing.app to a separate freshly installed machine and attempt to run it. Which I get the following error:

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

    dyld: Library not loaded: /user/local/lib/testing1.dylib Referenced from: /Users/me/testing.app/MacOS/./testing Reason: image not found

    我想念什么?

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

    Notes: When running install_name_tool, I need to use sudo or I get the following errors:

    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(错误的文件描述符)

    install_name_tool: can't open input file: testing.1.dylib for writing (Permission denied) install_name_tool: can't lseek to offset: 0 in file: testing.1.dylib for writing (Bad file descriptor) install_name_tool: can't write new headers in file: testing.1.dylib (Bad file descriptor) install_name_tool: can't close written on input file: testing.1.dylib (Bad file descriptor)

    推荐答案

    您不需要将库复制到项目中.

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

    您不需要使用 sudo 来更改您拥有的文件的安装名称.您不拥有该库文件吗?也许您在某些第三方项目上进行了"sudo make install"?只是不要安装它并链接到构建目录中的一个.如果要构建此库,则在使用链接命令的命令行选项构建它时,应设置其安装名称.

    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.

    除非您使用基于 @rpath 的安装名称,否则您无需设置运行路径搜索路径.

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

    我怀疑Xcode实际上是链接到您在步骤1中从 复制的库,而不是您复制的副本以及随后修改了安装名称的副本.构建记录中的实际链接命令说什么?您在步骤 1 中从何处复制库?如果它来自/usr/lib或/usr/local/lib,则Xcode可能与此相对.

    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.

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

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