Declaration of void abort() throws different exceptions

試著忘記壹切 提交于 2019-12-22 10:26:50

问题


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?

回答1:


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.




回答2:


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.




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/8122478/declaration-of-void-abort-throws-different-exceptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!