未定义对 __cxa_end_cleanup' 的引用

undefined reference to __cxa_end_cleanup#39;(未定义对 __cxa_end_cleanup 的引用)

本文介绍了未定义对 __cxa_end_cleanup' 的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个 C++ 项目,但是当它完成时会引发此错误:

I'm trying to build a C++ project however as it finishes it throws this error:

undefined reference to __cxa_end_cleanup'

使用的工具链是 ARM GCC 4.7.3,链接器自定义标志是:

The toolchain used is ARM GCC 4.7.3 and the Linker custom flags is:

-mthumb -march=armv6-m -T .Generated_SourcePSoC4cm0gcc.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 three choices,

  1. 更改构建选项.
  2. 提供库.
  3. 提供替代库.
  4. 避免函数调用/数据使用[这里不可能].

在这种情况下,伊恩·兰斯·泰勒给出了需要 -lsupc++ 的答案.此外,如果您使用的是 gcc,您应该切换到 g++,它会为您的 C++ 二进制文件添加适当的库.手册中提供了更多信息.

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.

如果你是深度嵌入的,你可以尝试用这个函数编写你自己的库.来源to __cxa_end_cleanup() 在这种情况下可供参考.看起来该功能是在异常条件或 exit() 期间恢复寄存器.如果您不使用该功能,则可以存根该功能(风险自负);但代码相当小,即使在 Cortex-M 上,我也会链接到提供的库.

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.

这篇关于未定义对 __cxa_end_cleanup' 的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:未定义对 __cxa_end_cleanup' 的引用

基础教程推荐