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

发布于 2024-12-15 09:49:42 字数 1062 浏览 4 评论 0原文

我正在尝试为 Festival 编写一些 C++ 代码(使用 C++ API),但在尝试编译时遇到了困难。以下是我调用 g++ 的方法:

g++ -Wall -pedantic -I../ -I../speech_tools/include/ helloFestival.C -oh -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 ()’

EST_String.h 中的违规行将是:
extern "C" void abort(void);

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

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

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

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

I am trying to write some C++ code (using the C++ API) for Festival and am getting stuck while trying to compile. Here is how I invoke 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
The error I get is:

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 ()’

The offending line in EST_String.h would be:
extern "C" void abort(void);

The main() function I have used can be found here: festvox.org/docs/manual-1.4.3/festival_28.html#SEC133

The compilation and linking instructions given here are the ones I have used.

I have looked this problem on the net and some of the solutions suggest that it maybe because of backward compatibility, or calling an abort() from within a destructor etc. My questions are:

  1. How do I get rid of this?
  2. Why do I see this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等待圉鍢 2024-12-22 09:49:42

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

如果不是,请勿将 stdlib.h 和 EST_String.h 包含在同一文件中。是的,这有限制而且很糟糕,但你现在的处境很糟糕。

You see this error because the abort() function in speech_tools conflicts with the standard-mandated abort() function. There's probably no really good, clean way to fix this. If you have written EST_String.h yourself, name the function differently.

If not, don't include stdlib.h and EST_String.h in the same file. Yes, that's limiting and bad, but you are in a crappy situation here.

猥琐帝 2024-12-22 09:49:42

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

It is a very basic c error. The two definition for abort are conflicting I would try to remove the line in EST_String.h and maybe add a #include <stdlib.h> and see if it compiles after that.

我最亲爱的 2024-12-22 09:49:42

我不认为包含 stdlib 标头是问题所在。但是,通过将 包含在内,您可能会获得更好的效果翻译单元中的第一个标头

理由:以防万一 中的定义添加了 no-throw declspec。

所以我真的建议......只是摆弄它。如果这两种方法都不起作用(确保没有冲突的包含或过时的预编译头),我建议删除 EST_String.h 中的违规声明

I don't suppose including the stdlib header is the problem. However, you might get better mileage from including either <cstdlib> or <stdlib.h> as the very first header in your translation units

Rationale: just in case the definition in <cstdlib> adds the no-throw declspec.

So I really suggest to ... just fiddle with that. If it doesn't work either way (make sure you don't have conflicting includes or stale precompiled headers), I suggest just removing the offending declarion in EST_String.h

紫南 2024-12-22 09:49:42

今天这仍然是一个问题。作为解决方法,我正在使用这段代码。
它很丑陋而且很老套,但可以正常工作:

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

This is still a problem today. As a workaround, i'm using this piece of code.
It's ugly and hacky, but gets it working:

extern "C" void abort_est() { abort(); }
#define abort abort_est
#include <festival.h>
#undef abort
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文