2009年9月23日 星期三

wxwidgets

This is an article that tells you how to install wxWidgets with DevCpp and MSYS.

wxWidgets is an cross-platform GUI library.  You may write an application almost without changing the code.  All you need is to re-compile the code on the OS you want.

DevCpp is an application that helps you writing in C and Cpp.  I always write C or Cpp program with it on Windows.

MSYS is an application that provide Windows user with Unix-like environment.

I'm going to show you how to use these to build an library and open an project under Windows.

1. Download the wxWidgets Library, DevCpp, and MSYS.

Any version of the wxWidgets Library is OK, but I prefer wxAll, which works for all OS.

2. Install DevCpp

Just use the default option.

3. Install MSYS

At the end of the installation, it will appear a console window.  This is asking you do you have any MinGW Compiler installed.  Since we install DevCpp, which automatically bundle the MinGW compilers.  For this question, the answer is YES.

Then, it will show another question in the console window.  The question is asking you where do you install the compilers.  You should type in "C:\Dev-Cpp\".

After you press enter, there still another question, which asking you if MSYS can change a program name to another.  I just follow the default option "YES", and I can't see what the difference after rename the file.

4. Extract wxWidgets

Just Extract, Using 7-zip or other similar tools.  Extract to "C:\" or other place you know. I install it in "I:\wxWidgets", which is an portable drive so that I can write code any where.

5. Setting Up Gloable Variable

Right click at "My Computer" and select Properties.  Click on the advanced tab then the 'environment variables' button.  In system variables, look for a variable called path and double click on it.  Add the following to the beginning of the value: "C:\Dev-Cpp\bin;c:\msys\1.0\bin;".

6. Build the Library

Note: My wxWidgets Library is Extract into "I:\wxWidgets".  You should know where your wxWidgets just Extract.

Open the MSYS from Desktop, following the following command to build the library.  Only the text in this style should be typed in to the window.
cd i:  => To change directory
cd wxWidgets => change directory to I:\wxWidgets
cd wxWidgets-2.9.0 => change directory to I:\wxWidgets\wxWidgets-2.9.0
mkdir mswDebug => make a directory named "mswDebug"
cd mswDebug => change directory to I:\wxWidgets\wxWidgets-2.9.0\mswDebug
../configure --enable-debug => to setup library, this may takes a while
make => to build the library, this may takes a while, too
make install => to install the library to the MSYS, this may also takes a while
Follow the step above should have no error.  The last three command will take some time, you MUST WAIT until the screen stop and you can enter command.

6. Setting Up DevCpp Project

Here, I WILL NOT tell you how to write wxWidgets program.  Here, I only tell you what you should set before compiling the project.

Goto the "Project/Project Options" to open the option dialog.

In "General" tab, the "Type" of the application is "Win32 GUI".

Type "wx-config --cppflags" in MSYS, copy the text appear on the screen.  NOT ALL THE TEXT SHOULD YOU COPY. Just copy the text that after -D.  For Example, my screen pop up as "-I/usr/local/lib/wx/include/msw-unicode-debug-2.9 -I/usr/local/include/wx-2.9 -D_LARGEFILE_SOURCE=unknown -D__WXDEBUG__ -DWXUSINGDLL -D__WXMSW__", you just copy the text that is marked as this.  And then paste them into the "C++ compiler" in the "Parameters" tab.

Type "wx-config --libs" in MSYS.