“代码生成错误,Boost 中的指针差异” 32 位构建时出错

发布于 2024-11-09 03:39:41 字数 412 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

獨角戲 2024-11-16 03:39:41

问题很可能是您将两个具有不同默认可见性值(-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.

城歌 2024-11-16 03:39:41

您可能正在链接使用 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.

辞慾 2024-11-16 03:39:41

欲了解更多信息:
在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.

淡忘如思 2024-11-16 03:39:41

该问题似乎已在随 XCode 4.2 安装的链接器中得到解决。链接后,我现在收到警告而不是错误消息:

ld: warning: direct access in __ZN5boost6detail15sp_counted_baseC2Ev to global weak symbol __ZTVN5boost6detail15sp_counted_baseE means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

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:

ld: warning: direct access in __ZN5boost6detail15sp_counted_baseC2Ev to global weak symbol __ZTVN5boost6detail15sp_counted_baseE means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
凹づ凸ル 2024-11-16 03:39:41

正如此处所述:

如果多个项目包含 boost,则每个项目必须具有相同的值

 Symbols Hidden by Default
 Inline Methods Hidden

As said here:

If boost is included by multiple projects, each project must have the same values for

 Symbols Hidden by Default
 Inline Methods Hidden
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文