Reputation: 5359
I am using STM32 dev board with MCU G++ Compiler & Linker: arm-none-eabi-g++
. However, it seems not compatible with STL:
#include <list>
int main (void)
{
std::list<int> list;
list.push_back(1);
list.sort();
return 0;
}
The linker error messages:
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'
The C++ STL seems dependent on operating systems. Since the micro-controller has no such things, those essential parts are missing while linking ELF.
The problem is how can I use STL on STM32 L4-series chips?
Upvotes: 3
Views: 3308
Reputation: 26
The C Standardlibrary needs some basic functions (called stubs) to work properly. Normally the OS provides these functions.
-specs= nosys.specs provides very dumb versions of these functions. In your compiler path under /share/doc/gcc-arm-none-eabi/pdf there should be a pdf libc.pdf there you will find some information how to implement those stubs yourself (chapter Systemcalls).
Upvotes: 1
Reputation: 5359
This problem can be solved by adding -specs=nosys.specs
to the G++ linker. This links in a separate library with implementations for all required system functions.
See also: http://pabigot.github.io/bspacm/newlib.html
Upvotes: 2