Using Dev-C++ with wxWidgets |
by Julian Smart, September 2002
Updated April 2003
Dev-C++ is a free
Windows IDE (Integrated Development Environment) which brings you, for free,
some of the convenience of editing, compiling and debugging applications that many IDE users
are used to with commercial products.
This page helps you set up Dev-C++ for wxWidgets. There are instructions for using version 4 (manual setup) and version 5 (DevPak setup).
Another method is to just import the VC++ project file (.dsp) from the wxWidgets src directory, add appropriate include and resource directories in the converted .dev project, copy and change setup.h, then press F9.
These instructions refer to the stable Dev-C++ 4, and wxWidgets 2.3.3. If you are using wxWidgets 2.2.x, you will need to adjust some of the flags, for example adding -lxpm and renaming -lwxmswd to -lwx.
Also, if you use the wxWidgets DevPak, you can discount these instructions: instead, all you have to do is open the Check For Packages/Updates under 'Tools' and download the wxWidgets DevPak. It auto-installs. Then you simply say New/Project/GUI/wxWidgets and you've got a basic wxWidgets app that compiles. (Note: sometimes it doesn't compile straight away because the DevPak forgets to put the command line options for the compiler under 'C++ compiler', only 'Compiler'. just simply go into the compiler options and copy, paste.)
Dev-C++ allows you to create projects, edit source files, specify switches to pass to the compiler and linker, and then compile and link your program without having to drop down to the command line and type 'make' as you would otherwise do with MinGW.
What about debugging? Well, Dev-C++ does come with a console-based version of gdb, which most users would find pretty lame. Instead, you can download Insight, which is a slightly clunky user interface built on top of gdb. But it's better than nothing, and becoming familiar with a debugger is essential if you're serious about writing interesting C++ applications.
Edit the file include/objidl.h at line 663 and add a missing PURE keyword. Change it from:
STDMETHOD(EnumDAdvise)(THIS_ IEnumSTATDATA**);to:
STDMETHOD(EnumDAdvise)(THIS_ IEnumSTATDATA**) PURE;
dir /cygdrive/c/wx2/include/wx:/cygdrive/c/wx2/include/wx/msw:/cygdrive/c/wx2/include/wx/generic:/cygdrive/c/wx2/src/common:/cygdrive/c/wx2/src/msw:/cygdrive/c/wx2/src/genericThis tells gdb (and in particular Insight) where to find source files. Change the directory according to where wxWidgets is on your system. The notation /cygdrive/c is equivalent to c: (gdb needs it to be this way).
set PATH=c:\apps\Dev-C++\bin;c:\apps\extras\bin;%PATH% set WXWIN=c:\wx2 cd c:\wx2\src\msw make -f makefile.g95 allThis will build a debugging version of wxWidgets. Please note that you can't currently use the 'configure' method of compilation since there is a conflict between the version of MinGW distributed with Dev-C++, and the MSYS package that you need to install to run configure (you get a cygwin1.dll error). Perhaps someone can work around that limitation.
If you wish to use MSYS instead of extras.zip, please add the line OSTYPE=msys to makeg95.env, and in src/msw/makefile.g95 replace the line:
$(COPY) $(WXDIR)/include/wx/msw/setup.h $@ with $(COPY) $(WXDIR)/include/wx/msw/setup.h $(subst $(BACKSLASH),/,$@)before building, to ensure that the setup.h gets copied to the correct location. Note that you should still invoke makefile.g95 from DOS and not from MSYS's shell, because of the Cygwin DLL conflict.
Click on File|New Project..., click on the GUI Toolkits tab, and then select wxWidgets. Click OK.
You are presented with a file dialog: create a new directory for your project with the Create New Folder tool, type the folder name such as myproject, navigate into the folder and save the project as e.g. myproject.
Bring up the Project Options dialog (Project menu, Project options command). Some of these options will have been filled in already by the template, but some won't. If they have been filled in, check that the directories are correct for you.
-lwxmswd -lcomdlg32 -luser32 -lgdi32 -lole32 -lwsock32 -lcomctl32 -lctl3d32 -lgcc -lstdc++ -lshell32 -loleaut32 -ladvapi32 -luuid -Lc:\wx2\lib
-fno-rtti -fno-exceptions -fno-pcc-struct-return -fstrict-aliasing -Wall -fvtable-thunks -D__WXMSW__ -D__GNUWIN32__ -DWINVER=0x400 -D__WIN95__ -DSTRICT -D__WXDEBUG__
c:\wx2\include;c:\wx2\lib\mswd
Now click on Options|Compiler options... to bring up the Compiler Options dialog.
Now hit the Run Project button. A window should appear.
To debug your program, stop running it in Dev-C++ and click on the Debug Project button. If you installed Insight correctly, the Insight window will come up as per the picture on the right, showing a rather arbitrary source file. Select the source file you're interested in from the combobox at the bottom left of the main window, and click on the left of the line you wish execution to stop at: say, Show(TRUE) in MainApp::OnInit.
Click on the Run icon, and the program should run until your breakpoint. You can now use the Step, Next, Finish, Continue etc. to step through your program. Bring up the local variables or watch windows to look at data in your program.
The gdb Console is useful for adding extra source directories, for example, and other commands you wish to feed to gdb directly. Dev-C++ comes with a gdb help file that you may wish to peruse. Insight's online help is pretty horrible to view.