eclipse ,cdt setup wxWidgets

来源:互联网 发布:电商erp软件 编辑:程序博客网 时间:2024/05/16 10:57
 

1、安装eclipse cdt和mingw

eclipse 只是个框架,实际编译还是mingw来执行的。

现在可以下载eclipse cdt的绿色包,里面已经包含了mingw,所以只需要下载这个绿色包即可。

2、编译wxWidgets库

This part is more interesting as the section about MinGW. First, if you haven't done it already, download wxWidgets-2.8.x.tar.bz2. I unpacked it and moved the unpacked directory to "C:\wxWidgets-2.8.x". Now let's open the command prompt and go to "c:\wxWidgets-2.8.x\build\msw". To compile wxWidgets with MSW you have to enter:

mingw32-make -f makefile.gcc BUILD=debug SHARED=0 UNICODE=1 USE_ODBC=1

Note: This might take quite a while (circa 10-30 minutes).

As of January 30, 2008 this does not quite work. makefile.gcc makes directories and deletes files and than errors on "/usr/bin/sh -c". To do a build with MinGW follow the instructions here: Compiling WxWidgets With MSYS-MinGW. However, TDM's MinGW Installer (tested with version 1.902.0) plays very nicely with wxWidgets-2.8.9 and compilation works till the end (tried March 3, 2009).

At this point, wxWidgets should be compiled and the libraries will be at "C:\wxWidgets-2.8.x\lib\gcc_lib\mswud". The last directory name shows you that it is compiled with UNICODE and DEBUG options. To compile RELEASE libraries you have to enter the same like above but change the BUILD-option.

mingw32-make -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 USE_ODBC=1

While compilation, following libraries are created inside the "C:\wxWidgets-2.8.x\lib\gcc_lib" directory:

BUILD=debug

libwxbase28ud.a libwxbase28ud_net.a libwxbase28ud_odbc.a libwxbase28ud_xml.a libwextpatd.a libwxjpegd.a libwxmsw28ud_adv.a libwxmsw28ud_aui.a libwxmsw28ud_core.a libwxmsw28ud_dbgrid.a libwxmsw28ud_html.a libwxmsw28ud_media.a libwxmsw28ud_richtext.a libwxmsw28ud_xrc.a libwxpngd.a libwxtiffd.a libwxzlibd.a

BUILD=release

libwxbase28u.a libwxbase28u_net.a libwxbase28u_odbc.a libwxbase28u_xml.a libwextpat.a libwxjpeg.a libwxmsw28u_adv.a libwxmsw28u_aui.a libwxmsw28u_core.a libwxmsw28u_dbgrid.a libwxmsw28u_html.a libwxmsw28u_media.a libwxmsw28u_richtext.a libwxmsw28u_xrc.a libwxpng.a libwxtiff.a libwxzlib.a

Two more directories are created, one named "mswud" and the other one named "mswu"

[edit]Test

For testing, go to a sample directory e.g. (in my case) "c:\wxWidgets-2.8.x\samples\minimal" and compile it with the same options as you compiled the wxWidgets.

mingw32-make -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 USE_ODBC=1

If you don't do that, the libraries won't be found!

3、eclipse config

To configure eclipse we must - of course - start eclipse first. During startup the workspace launcher will appear on the screen. Define whatever you want. When the startup of eclipse is finished we need to change to the c++ perspective. So click in eclipse on Window/Open Perspective/Other.... Chose c++ and click on ok. The appearance will change to the c++ perspective.

Now let's create a new project. Click on File/New/Managed Make C++ Project. A New Project dialog should be now on the screen. Enter the project name, in this example minimal to see if we can compile the minimal sample of the wxWidgets source. Now you can change the workspace location for this project if you like. In my case I changed the location to "U:\Daten\programming\wxWidgets\minimalWidget". Click Next. Project Type should be "Executable (Gnu on Windows)" and in the configurations section chose (if isn't already done) both, means Debug and Release. Click again on Next. Now you can click without any change on Finish.

[edit]Debug configuration

Now we will check which configuration is currently active. For this, click on "Project/Active Build Configuration/". Please be sure the debug configuration is active. If you have done this part click on the created project to mark the name minimal. Than a right-click with the mouse and chose "Properties". Now the "Properties for minimal" dialog will open on the screen.

Please click on C/C++ Build. In the Active configurationDebug should be visible, if not change it to Debug. For the next step, go to the Environment tab and under Environment variables the Configuration tab should be activated. Click on New to create a new User Variables. Enter PATH. Now your complete system path should appear in the Value field. Delete everything excepting the path to your MinGW installation e.g. "C:\MinGW\bin". Delimiter should be ; and in the field Operation chose Replace. Click on OK.

Now go to the Tool Settings tab. In the GCC C++ Compiler section click on Preprocessor (attention: in CDT 3.1.2 you will find the symbols under the seperate option Symbols, directly under Preprocessor). Add to Defined symbols (-D)__WXMSW__ (attention, please make 2 underscores before AND after WXMSW), __WXDEBUG__ and _UNICODE (only one underscore and of course only if you have compiles the libraries with unicode support). Than you can change to Directories. Add to Include paths (-I) "C:\wxWidgets-2.8.0\lib\gcc_lib\mswud" (in my case!!!), "C:\wxWidgets-2.8.0\include" and "C:\wxWidgets-2.8.0\contrib\include". Now you can change to Miscellaneous and enter in the field Other flags-c -Wundef -Wno-ctor-dtor-privacy -fno-strict-aliasing.

Now make a jump to the "GCC C++ Linker" section. Click on "Libraries". Enter the libraries in the following order:

wxmsw28ud_xrc wxmsw28ud_richtext wxbase28ud_net wxmsw28ud_dbgrid wxbase28ud_odbc wxmsw28ud_media wxmsw28ud_aui wxmsw28ud_html wxmsw28ud_adv wxbase28ud_xml wxmsw28ud_core wxbase28ud wxtiffd wxjpegd wxpngd wxzlibd wxregexud wxexpatd kernel32 user32 gdi32 comdlg32 winspool winmm shell32 comctl32 ole32 oleaut32 uuid rpcrt4 advapi32 wsock32 odbc32

Add to "Library search path (-L)" (again in my case!!!) "C:/wxWidgets-2.8.0/lib/gcc_lib" and "C:/wxWidgets-2.8.0/lib". Now the last change, click on "Miscellaneous" and enter in the field "Linker flags" -Wl,--subsystem,windows -mwindows. Click on Apply.

And last but not least, go to "Build Settings" tab, uncheck "Use default command", and enter new build command as "mingw32-make -f makefile". This will have Eclipse use mingw32-make rather than make command. That's it, click on Apply and then on OK.

That's all. Let's go and enjoy!

[edit]Test the debug configuration

To test this configuration, I copied the minimal.cpp, minimal.rc, sample.ico into my project workspace. Press F5 will update the screen (maybe you have to press F5 several times, eclipse isn't very fast!!) and the files should be visible under the minimal directory. Mark minimal again and click on "Project/Build Project". BTW, I deactivated the build automatically. Now you should be able to compile and run the debug binary.

[edit]Release configuration

Do the same like under Debug configuration. The library names shouldn't have a d at the end. In the "Preprocessor" section, you don't have to define __WXDEBUG__. That's it.

4、可能有些库的名字不一样,碰到不一样的药该过来,但是,顺序是不能变的。

原创粉丝点击