2012-05-31 78 views
1

我正在嘗試爲集成/移動平臺構建C++庫。該平臺有一個體面的庫,包括stdC++。我試圖建立的庫使用了流,並且每當它嘗試使用依賴於流的類時,我都會遇到'bad_cast'異常。這個std :: ostream相關的堆棧跟蹤是什麼意思?

0 0xb082d9b1 in SignalKill() 
    from /home/preet/bbndk-2.0.1/target/qnx6/x86/lib/libc.so.3 

1 0xb081aa7e in raise() 
    from /home/preet/bbndk-2.0.1/target/qnx6/x86/lib/libc.so.3 

2 0xb0818cb8 in abort() 
    from /home/preet/bbndk-2.0.1/target/qnx6/x86/lib/libc.so.3 

3 0xb87c48bf in __gnu_cxx::__verbose_terminate_handler() 
    at ../../../../../libstdc++-v3/libsupc++/vterminate.cc:93 

4 0xb87c23d6 in __cxxabiv1::__terminate (
    handler=0xb87c47c0 <__gnu_cxx::__verbose_terminate_handler()>) 
    at ../../../../../libstdc++-v3/libsupc++/eh_terminate.cc:38 

5 0xb87c2421 in std::terminate() 
    at ../../../../../libstdc++-v3/libsupc++/eh_terminate.cc:48 

6 0xb87c2563 in __cxxabiv1::__cxa_throw (obj=0x859e710, tinfo=0xb87f4c24, 
    dest=0xb87c0670 <std::bad_cast::~bad_cast()>) 
    at ../../../../../libstdc++-v3/libsupc++/eh_throw.cc:83 

7 0xb875e88c in std::__throw_bad_cast() 
    at ../../../../../libstdc++-v3/src/functexcept.cc:52 

8 0xb8798c0d in __check_facet<std::ctype<char> > (__f=<optimized out>) 
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/bits/basic_ios.h:49 

9 widen (__c=<optimized out>, this=<optimized out>) 
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/bits/basic_ios.h:440 

10 std::endl<char, std::char_traits<char> > (__os=...) 
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/ostream:539 

11 0xb8793c2d in std::ostream::operator<< (this=0x84db220, 
    __pf=0x804f64c <[email protected]>) 
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/ostream:113 

12 0x0805240d in QDecViewport::QDecViewport (this=0x86da6c0, parent=0x0) 
    at ../qml_osg_viewport/qdecviewport.cpp:12 

13 0x08051cca in QDeclarativePrivate::QDeclarativeElement<QDecViewport>::QDeclarativeElement (this=0x86da6c0) 
    at /usr/local/Trolltech/QtLighthouse-4.8.2-i386/include/QtDeclarative/qdeclarativeprivate.h:83 

14 0x08051d3c in QDeclarativePrivate::createInto<QDecViewport> (
    memory=0x86da6c0) 
    at /usr/local/Trolltech/QtLighthouse-4.8.2-i386/include/QtDeclarative/qdeclarativeprivate.h:91 

15 0xb8ad5ec5 in ??() 

16 0x086da6c0 in ??() 

17 0x00000000 in ??() 

框架7-11是相關的,我需要幫助理解。代碼幀12所指的行只是:

OSG_INFO << "Hello OSG" << std::endl; 

其中OSG_INFO是用於記錄的流重定向器。我可以用同樣的方式使用std :: cout而不會有任何問題。 Unmangling框架11給我:

__pf=0x804f64c <std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)@plt>) 

這仍然是相當神祕的...我想要了解的東西快要瘋了,如果可能我是想通過一些奇怪的東西到ofstream的輸出操作,但它只是文本。有沒有人有什麼建議?

+2

除了ildjarn說的話,似乎安裝到流中的某些方面沒有實現正確的類型('__check_facet'中的'dynamic_cast'失敗)。你在使用任何自定義方面? –

回答

3

std::endl具有以下行爲,援引C++ 11§27.7.3.8/ 1:

呼叫​​,然後os.flush()

架9說endl的號召,widen失敗,即是OSG_INFO.widen('\n')失敗。 widen,反過來,有以下行爲(§27.5.5.3/ 12):

返回:use_facet< ctype<char_type> >(getloc()).widen(c)

use_facet本身將引發bad_cast如果面是不存在的語言環境魔(§22.3.2/ 3),但你的堆棧跟蹤並不表明這種情況。 (話又說回來,我沒有通過的libstdC++內部挖出來驗證它是由本書做的事情...)

我認爲之前use_facet(或use_facet從堆棧跟蹤內聯和消失)__check_facet被稱爲,具有相同的淨效應;這意味着OSG_INFO已經充斥着一些不具備std::ctype<char>方面現在–糟糕時代的地方!

或者,它可能已經融入了一些帶有方面的語言環境,這些語言環境根本無法妥善處理widen('\n')。但是無法確切知道,也沒有其他的我們可以告訴你,不知道OSG_INFO是什麼和/或它是如何實現的。

+0

感謝您的深刻解答。我需要仔細看看源代碼......和我的編譯過程。我擔心我可能意外地將兩個不同的STL鏈接起來,這可能會導致地區不匹配。 – Prismatic

相關問題