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?
The error: undefined reference to function show() has appeared on the terminal shell as predicted. To solve this error, simply open the file and make the name of a function the same in its function definition and function call. So, we used to show(), i.e., small case names to go further.
An “Undefined Reference” error occurs when we have a reference to object name (class, function, variable, etc.) in our program and the linker cannot find its definition when it tries to search for it in all the linked object files and libraries.
Whenever you get undefined errors, you are not linking something that satisfies your build options. You have three 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With