Sunday, June 14, 2009

Setting up Eclipse + wxWidgets 2.8.10

After we have built our Debug and Release versions of wxWidgets now I show you how to setup wxWidgets with Eclipse.

Pre-Requisites
- Eclipse
(I prefer the C++ Developers version. It's lighter than the standard version, it comes with the CDT plugin already installed and it solved me some problems I had with the standard version with the CDT manually installed. You can download it here)
- MinGW + MSYS
- Both Debug/Release versions of wxWidgets

Debug Setup
1. Start Eclipse
2. Go to File --> New C++ Project
Under Project Type choose Executable --> Empty Project and under Toolchains select MinGW.
Name your project whatever you like and click Finish.
3. Right click on your project and click on Properties and check that Configuration set to Debug.
4. Go to C/C++ Build --> Tool Chain Editor and where it says Current builder select Gnu Make Builder
5. Go to C/C++ Build and unckeck Use default build command and where it says Build command type mingw32-make
6. Go to C/C++ Build --> Environment
Click on Add and where it says Name type PATH.
Where it says Value copy your wxWidgets Debug bin directory path (mine is D:\wx-Debug\bin)
7. Go to C/C++ Build --> Settings --> GCC C++ Compiler
Where it says Command paste this line: g++ `wx-config --debug=yes --static=no --cxxflags`
8. Go to C/C++ Build --> Settings --> MinGW C++ Linker
Where it says Command line pattern cut the variable ${FLAGS} and paste it at the end of the line.
9. Go to C/C++ Build --> Settings --> MinGW C++ Linker --> Miscellaneous
Where it says Linker flags paste this line: `wx-config --debug=yes --static=no --libs`

That should be all for the Debug setup.

Release Setup
Starting from step 3 of the Debug setup guide change it this way:

1. Check that Configuration is set to Release
2. Go to C/C++ Build --> Tool Chain Editor and where it says Current builder select Gnu Make Builder
3. Go to C/C++ Build and unckeck Use default build command and where it says Build command type mingw32-make
4. Go to C/C++ Build --> Environment
Click on Add and where it says Name type PATH.
Where it says Value copy your wxWidgets Release bin directory path (mine is D:\wx-Release\bin)
7. Go to C/C++ Build --> Settings --> GCC C++ Compiler
Where it says Command paste this line: g++ `wx-config --debug=no --static=no --cxxflags`
8. Go to C/C++ Build --> Settings --> MinGW C++ Linker
Where it says Command line pattern cut the variable ${FLAGS} and paste it at the end of the line.
9. Go to C/C++ Build --> Settings --> MinGW C++ Linker --> Miscellaneous
Where it says Linker flags paste this line: `wx-config --debug=no --static=no --libs`

Add a c++ source file and copy this source inside to test the building:

#include <wx/wx.h>


class MyApp : public wxApp
{
virtual bool OnInit();
};

IMPLEMENT_APP(MyApp)


class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
};

enum
{
ID_Quit=1,
ID_About
};


bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("Hello World"), wxPoint(50,50),
wxSize(450,350));

frame->Connect( ID_Quit, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) &MyFrame::OnQuit );
frame->Connect( ID_About, wxEVT_COMMAND_MENU_SELECTED,
(wxObjectEventFunction) &MyFrame::OnAbout );

frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame*)NULL,-1,title,pos,size)
{
// create menubar
wxMenuBar *menuBar = new wxMenuBar;
// create menu
wxMenu *menuFile = new wxMenu;
// append menu entries
menuFile->Append(ID_About,_T("&About..."));
menuFile->AppendSeparator();
menuFile->Append(ID_Quit,_T("E&xit"));
// append menu to menubar
menuBar->Append(menuFile,_T("&File"));
// set frame menubar
SetMenuBar(menuBar);

// create frame statusbar
CreateStatusBar();
// set statusbar text
SetStatusText(_T("Welcome to wxWindows!"));
}

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(_T("wxWindows Hello World example."),_T("About Hello World"),
wxOK|wxICON_INFORMATION, this);
}


Let me know if you encounter any problems.
Thanks for reading.

0 comments:

Post a Comment