void abort()的声明会抛出不同的异常

Declaration of void abort() throws different exceptions

本文关键字:异常 声明 abort void      更新时间:2023-10-16

我正试图为Festival编写一些C++代码(使用c++ API),并且在试图编译时卡住了。下面是我如何调用g++:

g++ -Wall -pedantic -I../ -I../speech_tools/include/ helloFestival.C -o h -L../festival/src/lib/libFestival.a -L../speech_tools/lib/libestools.a -L../speech_tools/lib/libestbase.a -L../speech_tools/lib/libeststrings.a |& tee festival.runLog我得到的错误是:

In file included from ../speech_tools/include/EST.h:48,
                 from ../festival/src/include/festival.h:47,
                 from helloFestival.C:4:
../speech_tools/include/EST_String.h:50: error: declaration of ‘void abort()’ throws different exceptions
/usr/include/stdlib.h:513: error: from previous declaration ‘void abort() throw ()’

Estrongtring.h中有问题的行应该是:
extern "C" void abort(void);

我使用的main()函数可以在这里找到:festvox.org/docs/manual-1.4.3/festival_28.html#SEC133

这里给出的编译和链接说明是我使用过的。

我在网上看过这个问题,一些解决方案表明它可能是因为向后兼容性,或者从析构函数中调用abort()等。我的问题是:

  1. 我如何摆脱这个?
  2. 为什么我看到这个错误?

看到此错误是因为speech_tools中的abort()函数与标准强制的abort()函数冲突。可能没有真正好的、干净的方法来解决这个问题。如果您自己编写了Estrongtring.h,则以不同的方式命名该函数。

如果没有,不要在同一个文件中包含stdlib.h和Estrongtring.h。是的,这是限制和不好的,但你现在的情况很糟糕。

这是一个非常基本的c错误。中止的两个定义是冲突的,我会尝试删除EST_String.h中的行,可能会添加#include <stdlib.h>,看看它是否在那之后编译。

我不认为包括stdlib头是问题。但是,如果您将 <cstdlib> <stdlib.h>作为翻译单元

的第一个头,您可能会获得更好的效果。

理由:以防<cstdlib>中的定义增加了no-throw declspec。

所以我真的建议……随便摆弄一下。如果这两种方式都不起作用(确保没有冲突的包含或过时的预编译头文件),我建议只删除Estrongtring.h

中的违规声明。

这在今天仍然是个问题。作为一种变通方法,我使用这段代码。它是丑陋和粗糙的,但它可以工作:

extern "C" void abort_est() { abort(); }
#define abort abort_est
#include <festival.h>
#undef abort