对 __cxa_end_cleanup 的未定义引用 [英] undefined reference to __cxa_end_cleanup'

查看:79
本文介绍了对 __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_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 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.

如果你是深度嵌入的,可以尝试用函数编写自己的库.来源在这种情况下可以使用 __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 的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆