“代码生成错误,Boost 中的指针差异” 32 位构建时出错
在 Mac OS X 10.6 下,我正在构建一个链接到 boost 1.46 的 C++ 共享库。我正在使用随 Xcode 4.0 安装的命令行工具。
64 位构建工作正常。构建 32 位时,我在链接时收到以下错误消息:
ld: bad codegen, pointer diff in boost::detail::sp_counted_base::sp_counted_base()to global weak symbol vtable for boost::detail::sp_counted_basefor architecture i386
我发现的唯一解决方法是使用 g++-4.0 进行 32 位构建。我尝试过的其他编译器(g++-4.2、llvm-g++-4.2 和 clang++)都会产生上述错误。
Under Mac OS X 10.6 I am building a C++ shared library which links to boost 1.46. I am using the command line tools installed with Xcode 4.0.
The 64-bit build works fine. When building for 32-bit, I get the following error message upon linking:
ld: bad codegen, pointer diff in boost::detail::sp_counted_base::sp_counted_base()to global weak symbol vtable for boost::detail::sp_counted_basefor architecture i386
The only workaround I found is to use g++-4.0 for the 32-bit build. The other compilers I tried (g++-4.2, llvm-g++-4.2 and clang++) all produce the error above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
问题很可能是您将两个具有不同默认可见性值(-fvisibility)的库静态链接在一起。您可以确保对 boost 和您的项目使用相同的可见性标志,或者使用显式导出符号文件。
The issue is most likely that you're statically linking together two libraries with different values for the default visibility (-fvisibility). You can either make sure to use the same visibility flags for both boost and your project, or use an explicit export symbol file.
您可能正在链接使用 gcc 4.0 构建的库,该库具有与 gcc 4.2 和 clang 不兼容的 ABI。您应该重建与 gcc4.2 或 clang 一起使用的所有库,使用与主应用程序相同的编译器选项(特别注意选项“C++ 标准库类型”又名 STANDARD_C_PLUS_PLUS_LIBRARY_TYPE,该选项应始终设置为“静态”或“动态”)图书馆)。另一个有用的选项是“默认隐藏符号”,但要注意,启用该选项会隐藏令人讨厌的错误,如果您在使用不同选项/编译器编译的库之间传递 C++ 对象,这些错误就会出现。
you're probably linking a library built with gcc 4.0, which has incompatible ABI with gcc 4.2 and clang. You should rebuild all libraries used with gcc4.2 or clang, using same compiler options as your main application (particular note to the option "C++ standard library type" aka STANDARD_C_PLUS_PLUS_LIBRARY_TYPE which should be set to "static" or "dynamic" consistently in all libraries). Another useful option is "symbols hidden by default" but beware that enabling that would hide nasty bugs that would rise if you pass C++ objects between libraries compiled with different options/compilers.
欲了解更多信息:
在XCode中,可见性在Code Generation > 中设置。默认情况下隐藏内联方法和隐藏符号
将它们设置为 NO 可修复此问题。
这对应于 gcc -fvisibility-inlines-hidden 和 -fvisibility 标志。您可以使用它们仅调整代码的设置,而不是扰乱 boost。
For information:
In XCode, visibility is set in Code Generation > Inline Method Hidden and Symbols Hidden by default
Setting those to NO fixes this issue.
This corresponds in effet to gcc -fvisibility-inlines-hidden and -fvisibility flags. You may uses those to only adjust your code's setting instead of messing with boost.
该问题似乎已在随 XCode 4.2 安装的链接器中得到解决。链接后,我现在收到警告而不是错误消息:
The problem seems to be fixed in the linker that is installed with XCode 4.2. Upon linking I now get a warning instead of the error message:
正如此处所述:
如果多个项目包含 boost,则每个项目必须具有相同的值
As said here:
If boost is included by multiple projects, each project must have the same values for