Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to __cxa_end_cleanup'

Tags:

c++

arm

psoc

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?

like image 942
quarks Avatar asked Jul 28 '14 01:07

quarks


People also ask

How do you fix undefined reference error in C?

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.

What is undefined reference?

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.


1 Answers

Whenever you get undefined errors, you are not linking something that satisfies your build options. You have three choices,

  1. Change the build options.
  2. Provide the library.
  3. Provide an alternative library.
  4. 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.

like image 113
artless noise Avatar answered Sep 22 '22 17:09

artless noise