现象

在编译手工编码的 MpiProdave.cpp/MpiProdave.h 时,使用 DialogBlocks MinGW Debug (Non-Unicode)标准编译器设置发生编译错误如下。这种错误在其他 DialogBlocks 生成的某些 c++ 文件编译时也会出现。而使用 MinGW Unicode Debug 标准编译设置时则没有编译错误发生。

g++.exe -c -o MinGWDebug/MpiProdave.o -fno-pcc-struct-return -fstrict-aliasing -Wall -Wno-write-strings -D__WXMSW__ -D__GNUWIN32__ -D__WIN95__  -D__WXDEBUG__ -ggdb -O0 -Wall -Wno-write-strings -I"C:/wx/include" -I"C:/wx/contrib/include" -I"C:/wx/lib/gcc_lib/mswd" src\MpiProdave.cpp
*** In file included from C:/wx/include/wx/toplevel.h:317,
***                  from C:/wx/include/wx/dialog.h:17,
***                  from C:/wx/include/wx/msw/msgdlg.h:16,
***                  from C:/wx/include/wx/msgdlg.h:49,
***                  from src\MpiProdave.cpp:17:
*** C:/wx/include/wx/msw/toplevel.h:122: error: expected identifier before numeric constant
*** C:/wx/include/wx/msw/toplevel.h:122: error: expected `,' or `...' before numeric constant
*** C:/wx/include/wx/msw/toplevel.h:122: error: ISO C++ forbids declaration of `parameter' with no type
*** mingw32-make.exe: *** [MinGWDebug/MpiProdave.o] Error 1

分析

初步分析是因为 MinGW 的某些头文件中使用了 #define 定义某些宏,而这些宏的名称正好和 wxWdigets 里某些类成员函数的名称重复,例如 Yield, CretaeDialog 等,但对于参数的定义(主要指参数的个数)不同,因而引起了编译错误。

解决方案

在手工编码的 c++ 文件中,把 wxWidgets 头文件的包含语句移到文件前面作为最先被包含的头文件,如下所示:

出错的文件 MpiProdave.cpp:

#include "MpiProdave.h"
#include "RTDataSource.h"

#include "../../prodave/src/Mpi.h"

#include <stdexcept>
using namespace std;

#include "wx/msgdlg.h"
#include "wx/string.h"
#include "wx/thread.h"
#include "wx/log.h"
#include "wx/intl.h"

namespace autecs {
// ...

修改为:

#include "wx/msgdlg.h"
#include "wx/string.h"
#include "wx/thread.h"
#include "wx/log.h"
#include "wx/intl.h"

#include "MpiProdave.h"
#include "RTDataSource.h"

#include "../../prodave/src/Mpi.h"

#include <stdexcept>
using namespace std;

namespace autecs {
// ...

错误消除。

Leave a Reply

You must be logged in to post a comment.