2013-08-04 61 views
3

我的項目包括以下內容:GCC 4.8.1,C++ 11,共享庫和異常處理麻煩

  • 我的程序,在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. 

我的嘗試:

  • 從我的代碼中拋出相同的異常(靠近故障點):它被正確的處理程序捕獲;
  • 重新編譯SOCI與-std=c++11:沒有區別
  • 添加__attribute__((visibility("default")))的異常類:沒有區別
  • -u選項typeinfo - 相關符號擺弄:在行爲上沒有區別,符號出現在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,但必須失去了別的東西..

有什麼建議?


編輯

其實,這不是任何動態庫的問題。 我應該立即嘗試靜態編譯它 - 並節省大量的時間,因爲行爲不會真正改變。 (查看答案)

+0

你能用最小的例子重現它嗎? –

+0

@ n.m。我會嘗試。雖然我不確定它是如何「微乎其微」...... – vines

+0

一個主要功能,一個其他功能,一個拋出,一個捕獲,一個異常類,全部拆分爲共享庫和可執行文件。另外,nm -D在共享庫中顯示了什麼? –

回答

3

最後我想出了問題......哦,哦。

這並不是說,例外情況並未被捕獲! std::terminate的調用是在異常從析構函數中拋出時產生的,並且在C++ 11中默認情況下是不允許的。我面臨的實際問題是這樣的:Destructors and noexcept - 編譯器錯誤讓我不知道庫缺陷...

+1

僅供參考,SOCI bug已修復 - https://github.com/SOCI/soci/pull/192我很抱歉它沒有發生過。 – mloskot

+1

是的,我剛剛分手了,發現它已經在那裏了:) – vines