'undefined reference to __cxa_end_cleanup'
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?
Solution 1:[1]
Whenever you get undefined errors, you are not linking something that satisfies your build options. You have four choices,
- Change the build options.
- Provide the library.
- Provide an alternative library.
- Avoid the function call/data use
[impossible here].
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.
Solution 2:[2]
Add -lc++ to linker library list
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Karlis Ogsts |