简体   繁体   English

间接依赖Mac OS X的链接问题

[英]Linking issue with indirect dependencies on Mac OS X

we have some linking problems with indirect dependencies. 我们在间接依赖方面存在一些链接问题。 Guessing from what I read on the web it may be because of two-level namespace usage. 根据我在网上阅读的内容猜测,可能是由于使用了两级名称空间。 This happens when we link against a boost library, boost_filesystem to be precise, which itself depends on boost_system. 当我们链接到一个boost库时,就会发生这种情况,确切地说,boost_filesystem本身取决于boost_system。 The linker doesn't resolve the dependency between boost_filesystem and boost_system. 链接器无法解决boost_filesystem和boost_system之间的依赖关系。 Can someone give me some hints how this can be resolved? 有人可以给我一些提示如何解决吗? Adding boost_system manually to the dependencies feels ugly and besides, it works fine on other platforms. 手动将boost_system添加到依赖项并不容易,此外,在其他平台上也可以正常工作。

Some versions of the static link editor ld on Mac do not resolve indirect dependencies via the -L option and instead simply look them up via the install_name that is baked into the direct dependency. 在Mac上,某些版本的静态链接编辑器ld不能通过-L选项解决间接依赖关系,而只是通过包含在直接依赖关系中的install_name来查找它们。 Running otool -L on boost_filesysten will show you where ld is looking for boost_system. 在boost_filesysten上运行otool -L将显示ld在哪里寻找boost_system。

You can either change the install_name with install_name_tool or you can use the 您可以使用install_name_tool更改install_name,也可以使用

-dylib_file install_name:file_name -dylib_file安装名:文件名

option to ld which is just a way of telling ld that whenever it comes across an install_name path matching the part of the argument before the colon then it should actually get that library from the path after the colon. ld的选项,这只是一种告诉ld的方法,只要遇到与冒号前面的参数部分匹配的install_name路径,它实际上应该从冒号之后的路径获取该库。

I think that newer versions of ld now do respect -L for indirect dependencies on Mac but I'm not sure. 我认为较新版本的ld现在确实尊重-L对Mac的间接依赖关系,但是我不确定。 I've only used 10.4 which had an ld that ignored -L for indirect dependencies and I used -dylib_file to get rid of a lot of phantom explicit dependencies that other people had put in to get round the very problem you describe! 我只使用了10.4,它的ld忽略了-L的间接依赖关系,而我使用了-dylib_file摆脱了其他人为解决您描述的问题而引入的许多幻影显式依赖关系!

If boost_filesystem is using symbols from boost_system (and your application isn't), and is itself linking directly against boost_system to resolve them, it should just work. 如果boost_filesystem使用的是boost_system中的符号(而您的应用程序未使用),并且本身直接与boost_system链接以解析它们,则它应该可以正常工作。 The flat vs. two-level namespace problems generally rear their head when you expect symbols provided by a dependency of a library you're linking against to be available within your app. 当您希望链接的库的依赖项提供的符号在您的应用程序中可用时,通常会出现平面名称空间与两级名称空间问题。

If boost_filesystem isn't linking against boost_system (otool -L will tell you), then you've got little option—short of relinking it—except to add a manual dependency upon boost_system. 如果boost_filesystem没有链接到boost_system(otool -L会告诉您),那么您几乎没有选择-除了重新链接之外-除了对boost_system添加手动依赖项之外。

Am I right in thinking boost doesn't use GNU libtool (it handles inter-library dependencies in the correct platform-specific way for you)? 我是否认为Boost不使用GNU libtool(它以适合您平台的正确方式处理库间依赖关系)对吗? If it does, that might be an easy workaround. 如果是这样,那可能是一个简单的解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM