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. The linker doesn't resolve the dependency between boost_filesystem and 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库时,会发生这种情况,精确地说就是boost_filesystem,它本身依赖于boost_system。链接器不解析boost_filesystem和boost_system之间的依赖关系。有人能给我一些提示如何解决这个问题吗?手动将boost_system添加到依赖项感觉很难看,而且,它在其他平台上运行良好。
2 个解决方案
#1
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. Running otool -L on boost_filesysten will show you where ld is looking for boost_system.
Mac上的某些版本的静态链接编辑器ld不能通过-L选项解析间接依赖关系,而只需通过烘焙到直接依赖关系中的install_name查找它们。在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
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. 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!
我认为ld的新版本现在尊重-L对Mac的间接依赖,但我不确定。我只使用10.4有一个忽略-L的ld用于间接依赖,我使用-dylib_file来摆脱其他人为了解决你描述的问题而放入的许多幻影显式依赖关系!
#2
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. 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.
如果boost_filesystem正在使用来自boost_system的符号(并且你的应用程序不是),并且它本身直接与boost_system链接以解决它们,它应该可以工作。当您期望由您链接的库的依赖项提供的符号在您的应用程序中可用时,平面与两级命名空间问题通常会出现问题。
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)? If it does, that might be an easy workaround.
我是否正确认为boost不使用GNU libtool(它以正确的平台特定方式处理库间依赖关系)?如果是这样,那可能是一个简单的解决方法。
#1
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. Running otool -L on boost_filesysten will show you where ld is looking for boost_system.
Mac上的某些版本的静态链接编辑器ld不能通过-L选项解析间接依赖关系,而只需通过烘焙到直接依赖关系中的install_name查找它们。在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
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. 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!
我认为ld的新版本现在尊重-L对Mac的间接依赖,但我不确定。我只使用10.4有一个忽略-L的ld用于间接依赖,我使用-dylib_file来摆脱其他人为了解决你描述的问题而放入的许多幻影显式依赖关系!
#2
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. 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.
如果boost_filesystem正在使用来自boost_system的符号(并且你的应用程序不是),并且它本身直接与boost_system链接以解决它们,它应该可以工作。当您期望由您链接的库的依赖项提供的符号在您的应用程序中可用时,平面与两级命名空间问题通常会出现问题。
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)? If it does, that might be an easy workaround.
我是否正确认为boost不使用GNU libtool(它以正确的平台特定方式处理库间依赖关系)?如果是这样,那可能是一个简单的解决方法。