WxWidgets ライブラリを使用してプログラムに GUI を追加しようとしています。また、そこにすべての #include ステートメントを入れるヘッダー ファイルもあります ("All_Headers.h")。
単純な WxFrame (Hello world like) を含むヘッダー ファイルをヘッダー ファイル ("GUI.h") に追加しました。
問題は、(#include "GUI.h") を All_Headers.h に入れると、次のエラーが発生することです: (Kernel.obj と Crystall_Builder.obj は私のオブジェクト ファイルです)
1>Kernel.obj : error LNK2005: "protected: static struct wxEventTable const MyFrame::sm_eventTable" (?sm_eventTable@MyFrame@@1UwxEventTable@@B) already defined in Crystall_Builder.obj
1>Kernel.obj : error LNK2005: "protected: virtual struct wxEventTable const * __cdecl MyFrame::GetEventTable(void)const " (?GetEventTable@MyFrame@@MEBAPEBUwxEventTable@@XZ) already defined in Crystall_Builder.obj
1>Kernel.obj : error LNK2005: "protected: virtual class wxEventHashTable & __cdecl MyFrame::GetEventHashTable(void)const " (?GetEventHashTable@MyFrame@@MEBAAEAVwxEventHashTable@@XZ) already defined in Crystall_Builder.obj
1>Kernel.obj : error LNK2005: "public: __cdecl MyFrame::MyFrame(class wxString const &,class wxPoint const &,class wxSize const &)" (??0MyFrame@@QEAA@AEBVwxString@@AEBVwxPoint@@AEBVwxSize@@@Z) already defined in Crystall_Builder.obj
1>Kernel.obj : error LNK2005: "public: void __cdecl MyFrame::OnQuit(class wxCommandEvent &)" (?OnQuit@MyFrame@@QEAAXAEAVwxCommandEvent@@@Z) already defined in Crystall_Builder.obj
1>Kernel.obj : error LNK2005: "public: void __cdecl MyFrame::OnAbout(class wxCommandEvent &)" (?OnAbout@MyFrame@@QEAAXAEAVwxCommandEvent@@@Z) already defined in Crystall_Builder.obj
ただし、(#include "GUI.h") をメイン ファイル (Kernel.cpp) に入れると、正常に動作します。
このエラーの原因を見つける方法がわかりません。助けてください。
どうもありがとう
メインファイル (Kernel.cpp)
// #include "GUI.h" // If I put GUI.h in here it works fine
#include "All_Headers.h"
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( "Hello World",
wxPoint(50,50), wxSize(450,340) );
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}
GUI.h:
#ifndef GUI_H
#define GUI_H
#include "wx/wx.h"
class MyApp: public wxApp
{
virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
MyFrame(const wxString& title,
const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
enum
{
ID_Quit = 1,
ID_About,
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title,
const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append( ID_About, "&About..." );
menuFile->AppendSeparator();
menuFile->Append( ID_Quit, "E&xit" );
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, "&File" );
SetMenuBar( menuBar );
CreateStatusBar();
SetStatusText( "Welcome to wxWindows!" );
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox("This is a wxWindows Hello world sample",
"About Hello World", wxOK | wxICON_INFORMATION, this);
}
#endif