본문 바로가기

C & C++

Setting up Eclipse + wxWidgets 2.8.10


** 주의 : 리눅스/유닉스용이다.  도중 exe파일 다운 받는 것은 신경쓰지 마시라.

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
  -> 다운로드 : https://sourceforge.net/downloads/mingw
                 Looking for the latest version? Download mingw-get-inst-20110802.exe (579.4 kB) 
  -> 설치 시 가능하면 폴더이름에 공백이나 한글이 없게 해야 설치가 가능하다.
- Both Debug/Release versions of wxWidgets
  -> 다운로드 : http://sourceforge.net/projects/wxwindows/files/2.9.2/wxWidgets-2.9.2.7z
  -> 압축 해제 후 : [설치폴더]\build\msw (윈도우용임) 에서 다음과 같이 command line으로 컴파일
      - DEBUG : make -f makefile.gcc BUILD=debug UNICODE=1 SHARED=0
        -> [설치폴더]\build\msw\gcc_mswud 생성됨
      - RELEASE : make -f makefile.gcc BUILD=release UNICODE=1 SHARED=0
        -> [설치폴더]\build\msw\gcc_mswu 생섬됨
      -> 컴파일 후 [설치폴더]\lib\gcc_lib 이 생성됨

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 typemingw32-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.

주) 공통사항 : 만일 C:\wxWidgets에 설치하지 않았다면 wx-config 옵션에 --prefix=[설치폴더] 옵션을 추가
                      어쩐일인지 setup.h를 찾지 못한다. 그래서 --wxcfg=gcc_lib\mswud 를 추가했다. 그러나!
                      gcc_dll\mswud를 찾는다.. ㅠㅠ;; 어쩔 수 없이 [설치폴더]\lib\gcc_lib을 복사해
                      [설치폴더]\lib\gcc_dll을 만들었더니.. 잘된다 ㅡ,.ㅡ;;; 버그랜다.. 이전 버전인데... 아직 안
                      고쳤나 보다.. ㅡ,.ㅡ;;
                     유니코드로 컴파일 했으므로 --unicode=yes 추가 잊지 말자!

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 typemingw32-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.

[출처] http://codereal.blogspot.com/2009/06/setting-up-eclipse-wxwidgets-2810.html