I am having difficulties using objects from the standard c++ template library. I get an "undefined reference to `__dso_handle'" linker error all the time. I just created a new STM32F405 Project and added a std::map object and used it in main, that's it.
Here is my configuration:
Eclipse: Kepler 2.0.2.20140224-0627
GNU ARM C/C++ Cross Compiler Support: 1.10.2.201407190854
GNU ARM C/C++ STM32Fx Project Templates: 2.2.1.201407120554
OS: Windows 8.1
Toolchain : GNU Tools ARM Embedded 4.8.2014q2
I tried instantiating 'std::map<char,int> first;' and initialising several items like 'first['a']=10;' worked, both on release and debug.</char,int>
Can you provide more details in order to reproduce the problem?
Sure, I created a new STM32F4xx Project, unchecked newlib nano.
Then added the following in main.cpp
Then added the following in the main function in main.cpp
Now rebuild:
I get a fault in _syscalls.c then, which requires me to add another include somewhere around line number 320 (I always get this fault btw).
The include which is missing for me in _syscalls.c is
and is not related to my main Problem I believe.
After this is fixed, I get the linker error 'undefined reference to....'.
I confirm the missing include in _syscalls.c, will be added to the next release
Just checked and it seems to work for release but not for debug ?!?
This is the linker Output btw :
the copied text is screwed due to the Markup... the actual Symbol is __dso_handle
nope, still does not reproduce.
did the following:
Debug:
Invoking: Cross ARM GNU Print Size
arm-none-eabi-size --format=berkeley "t2cppmap.elf"
text data bss dec hex filename
39604 2200 2844 44648 ae68 t2cppmap.elf
Finished building: t2cppmap.siz
Release:
Invoking: Cross ARM GNU Print Size
arm-none-eabi-size --format=berkeley "t2cppmap.elf"
text data bss dec hex filename
21608 2132 2712 26452 6754 t2cppmap.elf
Finished building: t2cppmap.siz
you probably have a different configuration, or did something differently.
any progress?
This seems to be an issue with g++ optimisations and '-fno-use-cxa-atexit' flag is suppose to fix it. But for some reason it didn't work for me all the time (sometimes changing -O0 to -O1 helped to get rid of the error).
Defining the following fixed it for me:
extern "C" void * __dso_handle;
It'll be good to know why '-fno-use-cxa-atexit' doesn't seem to work all the time though.
OK, having "--specs=nano.specs" option for "Other linker flags" also resolves the issue with __dso_handle.
the projects generated by the templates are supposed to use newlib-nano, otherwise several adjustments might be needed.