I'm trying to build a C++ project however as it finishes it throws this error:
undefined reference to __cxa_end_cleanup'
The toolchain used is ARM GCC 4.7.3 and the Linker custom flags is:
-mthumb -march=armv6-m -T .\Generated_Source\PSoC4\cm0gcc.ld -g -Wl,-Map,${OutputDir}\${ProjectShortName}.map -specs=nano.specs -Wl,--gc-sections
What is the general reason for the error above? And what linker flags would solve this error?
Whenever you get undefined errors, you are not linking something that satisfies your build options. You have four choices,
In this case, Ian Lance Taylor gives the answer that -lsupc++
is needed. Also, if you are using gcc
you should switch to g++
, which adds the proper libraries for your C++ binaries. Some more information is given in the manual.
If you are deeply embedded, you can try to code your own library with the function. The source to __cxa_end_cleanup()
is available in this case for reference. It looks like the function is to restore registers during exception conditions or exit()
. If you don't use the functionality, you could stub the function (at your own risk); but the code is fairly small and even on a Cortex-M, I would link with the supplied library.