我怎样才能得到X code到链接和调试与提高文件系统的应用程序? [英] How can I get Xcode to link and debug an app with Boost Filesystem?

查看:260
本文介绍了我怎样才能得到X code到链接和调试与提高文件系统的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR

Objective-C的应用程序与动态链接提高文件系统的静态库链接。应用程序可以从输出目录使用终端,而是试图从X code调试或Finder运行运行提供误差 dyld的:库未加载:libboost_filesystem.dylib<&剪断GT;原因:未找到图片

Objective-C app linked with static library that dynamic links Boost Filesystem. App can be run from output directory using Terminal, but trying to run from Xcode debugger or Finder gives error dyld: Library not loaded: libboost_filesystem.dylib <snip> Reason: image not found.

问题

在我的X code项目,我有一个看起来像这样的结构:

In my Xcode project I have a structure that looks like this:

MainProject (Objective-C)
 - static_lib_that_uses_filesystem (C++)

要得到的一切联系起来,我说libboost_system和libboost_filesystem dylibs的链接二进制与库的建立MainProject阶段。

To get everything to link, I added libboost_system and libboost_filesystem dylibs to the "Link Binary with Libraries" build phase in MainProject.

当我尝试从任X code或Finder中运行应用程序我得到:

When I try to run the app from either Xcode or Finder I get:

sharedlibrary apply-load-rules all
warning: Unable to read symbols for libboost_filesystem.dylib (file not found).
warning: Unable to read symbols from "libboost_filesystem.dylib" (not yet mapped into memory).
warning: Unable to read symbols for libboost_system.dylib (file not found).
warning: Unable to read symbols from "libboost_system.dylib" (not yet mapped into memory).
[Switching to process 43957 thread 0x0]
dyld: Library not loaded: libboost_filesystem.dylib
  Referenced from: /Users/ssteele/Library/Developer/Xcode/DerivedData/MainProject-dqrhyuarllykslftblocjdzxlran/Build/Products/Debug/MainProject.app/Contents/MacOS/MainProject
  Reason: image not found

我添加了一个构建阶段到dylibs复制到被捆绑的框架目录,这并不能帮助。我改变了这种把它们复制到可执行文件目录也没有帮助。

I added a build stage to copy the dylibs to the Frameworks directory in the bundle, this doesn't help. I changed this to copy them to the Executables directory which also didn't help.

让他们在可执行文件目录的确实的让我从终端上运行的应用程序。

Having them in the Executables directory does allow me to run the app from Terminal.

我怎样才能获得应用程序找到dylibs从Finder中/ X code运行时?

How can I get the app to find the dylibs when run from Finder/Xcode?

背景信息

我使用的是狮子X $ C $ 4.2Ç,目前只针对狮子。我建我的共享库文件系统是这样的:

I'm using Xcode 4.2 on Lion and currently targeting Lion only. I built my shared libraries for filesystem like this:

./b2 threading=multi macosx-version=10.7 --with-filesystem stage

这将创建libboost_system.dylib,libboost_filesystem.dylib,以及在舞台/ lib目录下。一个等价的,我在这个项目直接从那里引用它们。

This creates libboost_system.dylib, libboost_filesystem.dylib, and also .a equivalents in the stage/lib directory, I'm referencing them in the project directly from there.

推荐答案

在,他们应该从加载路径OSX烘动态库(dylibs)。例如...

Dynamic libs (dylibs) on OSX bake in the path that they should be loaded from. For example...

/usr/lib/some_awesome.dylib

当你链接到一个dylib,连接器嵌入在你的可执行文件,以寻找它在运行时发生此路径。这是好的,易于安装库,但对于相对路径来链接它更复杂了。

When you link to a dylib, the linker embeds this path in your executable as the place to look for it at runtime. This is fine and easy with installed libs, but for relative path linking it's more complicated.

当你构建升压库,他们只是得到他们的名字嵌入,而不是一个完整或相对路径(即 libboost_system.dylib ,而不是 / usr / lib目录/ libboost_filesystem.dylib )。你应该能够与 DLL路径选项,但这似乎打破目前

When you build the boost libs, they just get their names embedded rather than a full or relative path (i.e. libboost_system.dylib rather than /usr/lib/libboost_filesystem.dylib). You should be able to change this with the dll-path option, but that seems broken currently.

要解决你的问题,你要么需要以某种方式获得相对于嵌入式应用程序(例如: @ executable_path / libwhatever.dylib )插入到dylibs正确的路径,这将可能需要的bjam DLL路径选项工作,或替代你可以修复你的可执行文件在不同的位置看。

To fix your problem you either need to get the correct path relative to your application embedded (e.g. @executable_path/libwhatever.dylib) into the dylibs somehow, which would probably require the bjam dll-path option to work, or instead you can fix your executable to look in a different location.

要做到这一点,使用类似下面为您的构建脚本步:

To do this, use something like the following as a script step in your build:

install_name_tool -change libboost_filesystem.dylib @ executable_path / libboost_filesystem.dylib $ BUILT_PRODUCTS_DIR / $ EXECUTABLE_PATH

请注意,如果你有一个相互引用破​​碎的路径多dylibs,你需要修复它们之间的路径也是如此,例如

Note that if you have multiple dylibs that reference each other with broken paths, you'll need to fix the paths between them too, e.g.

install_name_tool -change libboost_system.dylib @executable_path/libboost_system.dylib$BUILT_PRODUCTS_DIR/$EXECUTABLE_FOLDER_PATH/libboost_filesystem.dylib

下面是一个很好的文章:创建工作dylibs

The following is a good article on this: Creating working dylibs

这篇关于我怎样才能得到X code到链接和调试与提高文件系统的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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