) Eclipse + wxWidgets Development Environment setup

Source: Internet
Author: User
Tags configuration settings wxwidgets
Document directory
  • Wxwidget configuration and preparation of decent Windows programs
  • ---- Richard Lee
Eclipse + wxWidgets Development Environment

I have been searching for a convenient C ++ GUI library. Finally, wxWidgets is handled today.

The general steps are as follows:
Step 1: Install eclipse and CDT
Step 2: install and configure mingw and Compiler
Step 3: Download and compile wxwidget
Step 4: Configure wxwidget in eclipse

 

How to configure wxwidget and write a decent windows program ---- Richard Lee

After reading most of the articles on the Internet, most of them won't solve any problems, and may go astray, wasting more time on the preparations.
Therefore, we need to write down the detailed steps of these configurations, hoping to give some advice to the later users, so we don't have to spend any time building the environment.
The general steps are as follows:

Step 1: Install eclipse and CDT
Step 2: install and configure mingw and Compiler
Step 3: Download and compile wxwidget
Step 4: Configure wxwidget in eclipse

After these four steps, I believe you can debug your window program normally.
OK. Let's start.

Step 1 install eclipse and CDT
This step is actually the simplest step. People who have used eclipse and installed plug-ins should do it quickly.
Download the latest version of Eclipse, to my write this article should be version 3.2, downloaded by the http://www.eclipse.org, of course, first you need to download JDK and install and register the environment variable path correctly (cut the bin directory path of your JRE to path), and then start eclipse to see the normal startup screen.
Go to the eclipse website to find the CDT and download it. Of course you should select the latest version for download.
After downloading the package, decompress the package and copy the unzipped files and folders to the original eclipse directory. Restart eclipse and create a new project. You should be able to see the C/C ++ project.
By now, your CDT is successfully installed.

Step 2: install and configure mingw and Compiler
This part mainly involves the download and installation configuration of mingw.
Because eclipse + CDT alone cannot complete C ++ project development, because at least the compiler and basic class library are missing, here we choose mingw tool, you need to go to the http://www.MinGW.org to download the latest mingw.
So far, the latest version is 5.0.2. What you download directly from its website should be a download client software of over 100 kb, and you need to continue downloading all the content, after running the downloaded file, follow the instructions. If you are downloading the compressed package, that is, only the required part, you can download the following parts.

  • Gcc-g00000000-3.4.2-20040916-1.tar.gz
  • Gcc-core-3.4.2-20040916-1.tar.gz
  • Mingw32-make-3.80.0-3.tar.gz
  • Mingw-runtime-3.9.tar.gz
  • Mingw32-make-3.80.0-3.tar.gz
  • Binutils-2.15.91-20040904-1.tar.gz
  • W32api-3.6.tar.gz

After the download is complete, first copy them to the same directory and decompress them under the same directory (for example, My mingw installation directory is c: \ mingw, all the seven compressed files must be directly decompressed in C: \ mingw ). Then, set the environment variable to make sure that the PATH environment variable contains "D: \ mingw \ bin". Finally, open the DOS console and enter GCC to verify that the environment variable is correctly set. If your dos console displays "no input file" and other related information, this step is complete.
Step 3: Download and compile wxwidget
The wxwidget is downloaded and installed by the http://www.wxWidgets.org, And the directory is optional.
After installation, go to your wxWidgets installation directory (for example: C: \ wxWidgets-2.8.0 \ build \ MSW) and execute the command here

Mingw32-make-F makefile. GCC build = release shared = 0 Unicode = 1 use_odbc = 1

The makefile. GCC file is used to compile the entire project. You will wait for about half an hour. After compilation, the directory is increased to over 800 mb, because some of them are intermediate files of. O,
Can be deleted.

After compilation, you will see a bunch of archive files with the. A extension under the installation directory (C: \ wxWidgets-2.8.0 \ Lib \ gcc_lib) (the Library file in Windows is. Lib
Linux. A) and several directories, such as mswu and mswud.
Step 3.

Step 4: Configure wxWidgets in eclipse

Start eclipse and create a managed C ++ project. After the project is created, right-click the project and select "properties". In the Properties dialog box, select the "C/C ++ build" option.
On the C/C ++ build option interface, select "tool Settings" in "configuration settings".
In tool settings, select "gcc C ++ compiler"-> "Preprocessor ",
Add the following to the defined symbols list:_ Wxmsw __(Note: Both sides are double underscores ),_ Wxdebug __And_ Unicode(Here is a single underline,
Because your wxWidgets is compiled using Unicode encoding, you must set this macro here. Otherwise, a large number of "undefined reference" will be received during compilation ").
Next, you need to select the directories item and add the include and Lib directories. here you need to add
"C: \ wxWidgets-2.8.0 \ Lib \ gcc_lib \ mswud"
"C: \ wxWidgets-2.8.0 \ Lib \ gcc_lib \ mswu"
"C: \ wxWidgets-2.8.0 \ include"
"C: \ wxWidgets-2.8.0 \ contrib \ include"
These four directories are imported into directories.
Next, enter the following sentence in other flags in the miscellaneous option below:

-C-wundef-wno-ctor-dtor-privacy-fno-strict-aliasing

Next, click "gcc C ++ linker. In this section, select "Libraries" and in the libraries column on the rightIn orderEnter the following Database Name:

Struct, wxbase28ud, wxmongod, wxregexud, wxexpatd, wxzlibd, wxregexud, wxexpatd, Kernel32, USER32, GDI32, comdlg32, winspool, winmm, shell32, comctl32, OLE32, oleaut32, UUID, rpcrt4, advapi32, wsock32, odbc32

Add all database names to the following directory in "library search path (-l)" in the following column:

"C:/wxWidgets-2.8.0/lib/gcc_lib"

C:/wxWidgets-2.8.0/lib"

After adding, select the "Miscellaneous" item in the Section and type "linker flags"

-Wl, -- subsystem, Windows-mwindows

Click application.

Switch to the "build Settings" tab, deselect the check box before "use default command" in "build command", and change the make command

Mingw32-make-fmakefile

Finally, click "OK" to make the settings take effect.

Here, you can try samples in wxWidgets, copy the code into your project, compile and run it, and check the results.

I think you should have succeeded ....

 

The following is the code of the first wxWidgets program:

# Include "wx/wx. H"
Using namespace STD;
Class MyApp: Public wxapp
{
Public:
Vrtual 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 ()

Implement_app (MyApp)

Bool MyApp: oninit ()
{
Myframe * frame = new myframe (wxt ("Hello World"), wxpoint (50, 50), wxsize (450,340 ));
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)
{
Wxmenu * menufile = new wxmenu;

Menufile-> append (id_about, wxt ("& about ..."));
Menufile-> appendseparator ();
Menufile-> append (id_quit, wxt ("E & xit "));

Wxmenubar * menubar = new wxmenubar;
Menubar-> append (menufile, wxt ("& file "));

Setmenubar (menubar );

Createstatusbar ();
Setstatustext (wxt ("Welcome to wxwindows! "));
}

Void myframe: onquit (wxcommandevent & wxunused (event ))
{
Close (true );
}

Void myframe: onabout (wxcommandevent & wxunused (event ))
{
Wxmessagebox (wxt ("This Is A wxwindows Hello World sample "),
Wxt ("about Hello World"), wxok | wxicon_information, this );
}

 

Note:
When compiling wxwietsMingw32-make-F makefile. GCC build = release shared = 0 Unicode = 1 use_odbc = 1
Shared = 0 indicates static compilation;Shared = 1 indicates dynamic compilation
Use_odbc = 1 is the default value (it can be set to 0): Use ODBC database
Use_gl = 1 is the default
(It can be set to 0): use OpenGL library
For detailed compilation options, see <wx/setup. h>

If dynamic compilation is used,Defined symbols(Predefined?)Must be definedWxusingdll. If the debug version is used, you must add the mingw Runtime Library mingwm10.dll.

As mentioned above: If you compile the debug version, you need to define_ Wxdebug __;The release version is not required.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.