我正在嘗試開發使用C++的裸機平臺的軟件。我不使用異常,RTTI和動態內存分配。 (在我的g ++標誌中使用「-fno-exceptions -fno-unwind-tables -fno-rtti -nostdlib」)。 我想重用std :: streambuf功能來讀/寫順序數據,所以我通過從std :: streambuf繼承來定義自己的流緩衝區。其結果是我編譯應用程序時收到分辨的引用:std :: streambuf實例在裸機C++
undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::basic_streambuf()'
undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::~basic_streambuf()'
undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::imbue(std::locale const&)'
undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::setbuf(char*, int)'
undefined reference to `std::basic_streambuf<char, std::char_traits<char> >::seekoff(long long, std::_Ios_Seekdir, std::_Ios_Openmode)'
...
的問題是:有沒有什麼辦法來實例彙編我像其他正常的模板中的std ::流緩衝功能,而試圖用一個在STDLIB?
更新:我完全知道-nostdlib帶走了整個運行時環境。這是我的意圖。我只是想在STL和BOOST中重新使用模板類,只使用新的位置。即使編譯器試圖生成對諸如「void operator delete(void *)」,「void __cxa_pure_virtual()」或「__aeabi_atexit()」等函數的調用,我也可以創建空的存根,因爲知道這些函數永遠不會被調用。問題是,是否有任何方法像任何其他模板一樣強制系統標題類的常規隱式實例化(在使用時)?
使用'-nostdlib'幾乎將整個運行時基礎從C++語言中提取出來;即使是像'new'和'delete'這樣的東西,如果沒有這些,就可能無法使用(請參閱http://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.what_is_libsupcxx)。http://stackoverflow.com/questions/3714167/g-without-libstdc-can-it-be-done-a-very-configurable-lightweight-libstd有一些參考。 –
如果不使用標準庫,則不能從任何'std'類派生。你需要放棄'-nostdlib'。 –
不要忘記'std :: streambuf'可能至少間接使用異常。 (它可能會使用'new',它會通過異常報告內存不足)。因此,如果指定'-fno-exceptions',則幾乎不可能使用'std :: streambuf'。 –