Problem about exception handling without RTTI
OSXにおいて、node-kyteaでlibkytea側でthrowされたstd::runtime_errorをキャッチできないという問題があり、はまってました。
原因は、node-gypが生成するMakefileに -fno-rttiが記述されていることでした。
Linuxのgccでは問題ないのですが、OSXのgccで以下のように共有ライブラリから例外がthrowされる状況で、-fno-rtti付きでコンパイルされると例外オブジェクトの型を特定できず、... ハンドラでしか処理できません。
tyr{ do_something(); // do_something in shared library } catch( std::exception& e ){ // handling std::exception and subclasses } catch( some_exception& e ){ // handling some_exception } catch( ... ) { }
node-kyteaでは、以下のように'GCC_ENABLE_CPP_RTTI'オプションを追加することでこの問題を回避してます。
https://github.com/hideo55/node-kytea/blob/master/binding.gyp
{ 'targets': [ { 'target_name': 'kytea', 'sources': ['src/node_kytea.cc'], 'cflags': ['-fexceptions'], 'cflags_cc': ['-fexceptions'], 'cflags!': ['-fno-exceptions'], 'cflags_cc!': ['-fno-exception'], 'libraries': ['-lkytea'], 'conditions': [ ['OS=="mac"', { 'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', 'GCC_ENABLE_CPP_RTTI': 'YES' } } ] ] } ] }