c++ - 使用具有不同编译器版本的 boost 库

标签 c++ gcc boost compiler-errors

我用 gcc 版本 4.6.3(在 3.2.0-29-generic#46-Ubuntu 中)编译了 boost 1.54。 然后,我使用这个 boost 库开发了我的库。由于我不想每次更改我的库时都重新编译 boost,所以我将已编译的 boost 静态库添加到我的 git 存储库中。

现在,我正在尝试在具有不同版本编译器的不同机器上编译我的库(尝试使用 gcc 4.4 和 gcc 4.7)。我的库编译正常,但在链接时打印以下错误。

`.text._ZN5boost16exception_detail10bad_alloc_D2Ev' referenced in section `.text._ZN5boost16exception_detail10bad_alloc_D1Ev[boost::exception_detail::bad_alloc_::~bad_alloc_()]' of ../external/lib/linux/64/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10bad_alloc_D2Ev[_ZN5boost16exception_detail10bad_alloc_D5Ev]' of ../external/lib/linux/64/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail14bad_exception_D2Ev' referenced in section `.text._ZN5boost16exception_detail14bad_exception_D1Ev[boost::exception_detail::bad_exception_::~bad_exception_()]' of ../external/lib/linux/64/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail14bad_exception_D2Ev[_ZN5boost16exception_detail14bad_exception_D5Ev]' of ../external/lib/linux/64/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED1Ev[boost::exception_detail::error_info_injector<boost::thread_resource_error>::~error_info_injector()]' of ../external/lib/linux/64/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED5Ev]' of ../external/lib/linux/64/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED1Ev[boost::exception_detail::error_info_injector<boost::lock_error>::~error_info_injector()]' of ../external/lib/linux/64/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED5Ev]' of ../external/lib/linux/64/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED1Ev[boost::exception_detail::error_info_injector<boost::condition_error>::~error_info_injector()]' of ../external/lib/linux/64/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED5Ev]' of ../external/lib/linux/64/libboost_thread.a(thread.o)
collect2: ld returned 1 exit status
make[2]: *** [libHazelcastClientShared_64.so] Error 1
make[1]: *** [CMakeFiles/HazelcastClientShared_64.dir/all] Error 2
make: *** [all] Error 2

PS:我也尝试用另一台具有相同编译器版本的机器进行编译。 (gcc 版本 4.6.3 和 Centos 6.4)

最佳答案

不保证 c++ ABI 在不同编译器版本之间保持一致。这会影响 c++ 名称修改,并可能导致您看到的链接器错误。您必须对所有库使用相同版本的 gcc。

最好的办法是让你的整个系统都使用最新支持的 gcc 版本。如果您的用户确实需要不同的编译器,那么您可以提供不同版本的库 - 每个要支持的编译器一个。

不能保证与使用不同编译器编译的库进行链接。对于静态和共享/动态 C++ 库都是如此。

另请参阅: 看看Unusual C++ linker error - 'Defined in discarded section' 似乎该问题的公认答案也是使用相同版本的 GCC 编译所有库。

关于c++ - 使用具有不同编译器版本的 boost 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22667114/

相关文章:

c - `char *array[size]` 和 `extern char **array` 的错误链接?

c++ - GCC 与 kerberos 链接以静态编译 CURL

c - x86_64:堆栈框架指针几乎没有用吗?

c++ - 在嵌入式环境中替代 boost::shared_ptr

c++ - kill syscommand 在 Catch2 测试用例中产生失败

c++ - 如何避免与 char* 一起提供长度?

c++ - 右值引用的底层

c++ - 运算速度

c++ - 内联使用静态数据初始值设定项

c++ - 使用 boost::lexical_cast 将 UUID 转换为字符串时出现 Boost 编译错误