2017-02-15 269 views
1

我正在使用帶有MCU G ++編譯器的STM32開發板&鏈接器:arm-none-eabi-g++。然而,這似乎與STL不兼容:如何在ARM Cortex-M芯片上使用STL?

#include <list> 

int main (void) 
{ 
    std::list<int> list; 

    list.push_back(1); 
    list.sort(); 

    return 0; 
} 

鏈接器的錯誤信息:

abort.c:(.text.abort+0xa): undefined reference to `_exit' 
fstatr.c:(.text._fstat_r+0x10): undefined reference to `_fstat' 
signalr.c:(.text._kill_r+0x10): undefined reference to `_kill' 
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid' 
writer.c:(.text._write_r+0x12): undefined reference to `_write' 
closer.c:(.text._close_r+0xc): undefined reference to `_close' 
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty' 
lseekr.c:(.text._lseek_r+0x12): undefined reference to `_lseek' 
readr.c:(.text._read_r+0x12): undefined reference to `_read' 

的C++ STL似乎依賴於操作系統。由於微控制器沒有這些東西,所以在連接ELF時,這些基本部件都會丟失。

問題是如何在STM32 L4系列芯片上使用STL?

+2

這些鏈接器消息不必對C++標準庫做任何事情。看起來你缺少newlib等的綁定。 –

+0

您可能需要安裝一個更新的[GCC](http://gcc.gnu.org/)交叉編譯器,或許還有其他的東西(交叉binutils,交叉libc)。這是系統管理和安裝相關和最近的構建工具的問題。 –

+0

@πάνταῥεῖ@BasileStarynkevitch我向鏈接器添加了'-specs = nosys.specs'標誌,然後沒有錯誤彈出!問題解決了。 –

回答

0

的C Standardlibrary需要一些基本的功能(稱爲存根)才能正常工作。通常操作系統提供這些功能。

-specs = nosys.specs提供了這些函數的非常愚蠢的版本。在/ share/doc/gcc-arm-none-eabi/pdf下的編譯器路徑中應該有一個pdf libc.pdf,在那裏你可以找到一些如何自己實現這些存根的信息(章節Systemcalls)。