gpt4 book ai didi

c++ - GCC 4.8.1、C++11、共享库和异常处理问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:42 25 4
gpt4 key购买 nike

我的项目包括以下内容:

  • 我的程序,主要是用 C++11 编写的(因此尝试在 C++03 模式下编译它是不切实际的)
  • 共享库(https://github.com/SOCI/soci),使用相同的编译器编译

SOCI 抛出我需要在我的代码中捕获的异常。它曾经与 GCC4.7.3 一起使用,但现在我已经迁移到 GCC4.8.1 它不再适用了:异常会通过所有处理程序(包括 catch(...))并导致终止:

terminate called after throwing an instance of 'soci::mysql_soci_error'
what(): Table 'brphrprhprh' doesn't exist
The program has unexpectedly finished.

我尝试过的:

  • 从我的代码中抛出相同的异常(靠近故障点):它被正确的处理程序捕获;
  • 使用 -std=c++11 重新编译 SOCI:没有区别
  • __attribute__((visibility("default"))) 添加到异常类:没有区别
  • typeinfo 相关符号调整 -u 选项:行为没有区别,符号在 nm 中显示为未定义输出。请注意,如果没有 -u,则根本没有:

    $ nm -D -C myprogram | grep soci | grep error
    U soci::soci_error::soci_error(std::string const&)
    000000000044013a W soci::soci_error::~soci_error()
    0000000000440124 W soci::soci_error::~soci_error()
    0000000000440124 W soci::soci_error::~soci_error()
    00000000004c43b0 V typeinfo for soci::soci_error
    U typeinfo for soci::mysql_soci_error
    00000000004c43d0 V typeinfo name for soci::soci_error
    U typeinfo name for soci::mysql_soci_error
    00000000004c60c0 V vtable for soci::soci_error
    U vtable for soci::mysql_soci_error

我还读了http://gcc.gnu.org/wiki/Visibility ,但一定还缺少其他东西..

有什么建议吗?


编辑

实际上,这不是任何动态库问题。 我应该立即尝试静态编译它 —— 这样可以节省很多时间,因为行为实际上不会改变。 (看答案)

最佳答案

最后我想通了这个问题......哦。

并不是异常没有被捕获!对 std::terminate 的调用是在从析构函数中抛出异常时进行的,这在 C++11 中默认是不允许的。我面临的实际问题是:Destructors and noexcept -- 编译器错误让我没有意识到库错误...

关于c++ - GCC 4.8.1、C++11、共享库和异常处理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18044666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com