我的項目包括以下內容: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,但必須失去了別的東西..
有什麼建議?
編輯
其實,這不是任何動態庫的問題。 我應該立即嘗試靜態編譯它 - 並節省大量的時間,因爲行爲不會真正改變。 (查看答案)
你能用最小的例子重現它嗎? –
@ n.m。我會嘗試。雖然我不確定它是如何「微乎其微」...... – vines
一個主要功能,一個其他功能,一個拋出,一個捕獲,一個異常類,全部拆分爲共享庫和可執行文件。另外,nm -D在共享庫中顯示了什麼? –