void abort()的声明会抛出不同的异常
Declaration of void abort() throws different exceptions
我正试图为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()等。我的问题是:
- 我如何摆脱这个? 为什么我看到这个错误?
看到此错误是因为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
- 在类声明中初始化 const 成员变量时在调试模式下出现异常
- 声明一个额外的变量会导致运行时出现异常
- 异常声明错误
- 程序在函数声明时崩溃,出现未经处理的异常:堆栈溢出
- 我应该声明我的异常的副本构造函数noexcept吗
- 异常规格作为函数声明中的注释
- 异常变量声明
- 为什么必须声明异常
- 需要接受教育:声明"void encrypt(char*, int)"具有不同的异常说明符"
- 错误 C2248:无法访问在类中声明的私有成员,编译器行为异常
- 在变量声明上捕获异常
- 如果全局变量的声明引发异常,如何退出C++程序
- 来自异常声明的派生对象类型是否意外
- 硬关闭控制台/C++ 后的 fstream 声明异常
- g++-4.8.1认为没有异常说明的显式声明的析构函数总是noexcept(true)
- 使用显式实例化声明删除反向指针会导致 std::bad_weak_ptr 异常
- void abort()的声明会抛出不同的异常
- 拆分定义和声明时,定义不同的异常说明符
- 声明多维数组时的异常
- 异常规范在声明和功能实现方面不兼容