Compiling using MS VC++

From WxWiki
Jump to: navigation, search

Note: in what follows, "c:\wx2" is the base folder in which you installed wxWidgets. Replace this with your own folder name.

For instructions on how to set the project settings for a wxWidgets project manually, read the document here. Gotchas are:

  • Make sure you create an empty Win32 project, not a console application.
  • Your Win32 application should use the shared multithreaded DLLs. The debug one for debug build and the release for release, obviously.
  • In the debug config add __WXDEBUG__. You will need to make sure wxWidgets has this defined in its debug config as well.
  • Check if wxWidgets has <tt>WINVER=0x0400</tt> defined. If so then so should you. You may not notice problems until runtime if there is a mismatch. You may get errors saying that the calling convention is inconsistent.
  • (2.4.0 and later) In 2.4.0 the location of setup.h has changed. This is documented in the changes.txt. The main implication is that you need to add to "c:\wx2\lib\mswxxx" to the "additional include directories" for each build type. Check the lib folder for the possible options for xxx.
  • (2.4.0 and later) You can create a project by copying a sample, e.g. minimal. However, if you copy it out of the wxWidgets installation tree then you will have to replace all "../.." and "..\.." in the .dsp project file with the path to the installation (or use $(WXWIN) - see below).
  • If you want to automatically use different builds of wxWidgets then define the environment variable WXWIN and use that in the Settings rather than "c:\wx2" like "$(WXWIN)\lib\msw". You can't use this in Tools | Options | Directories so the $(WXWIN)\include folder could be put in the "additional include directories" for the project.
  • To define WXWIN on XP, goto System > Advanced > Environment Variables; and define a new value (you must restart VC for changes to take effect)

The setup.h problem can occur with some of the samples. If you get

--------------------Configuration: dialogs - Win32 Debug--------------------
Compiling resources...
Compiling...
dialogs.cpp
..\..\include\wx/platform.h(85) : fatal error C1083: Cannot open include file: 'wx/setup.h': No such file or directory
Error executing cl.exe.

then go into Project|Settings|C++ (this is MSVC6) and add

/I "c:\wx2\lib\mswd"

Simpler solutions

  • "wizard" for creating a bare-bones wxWidgets applications, but unfortunately it's a bit messy and outdated. It'd be cool if someone cleaned it up a bit. It's in the contrib section of the wxWidgets download pages.
  • Learn how to use Bakefile: it will save you a lot of time ! A bakefile template for wx-based application is here. Since wx 2.6.0 you can find a file called "bakefile_quickstart.txt" in wx/build/bakefiles/wxpresets folder: don't miss it !

If this fails, you could try the following:

  • load minimal.dsp into your text editor
  • do global search and replace of minimal to your program name
  • save as your_program.dsp