Compiling wxWidgets 2.6.2 to develop Code::Blocks (MSW)

From CodeBlocks
Revision as of 00:04, 20 April 2006 by Sethjackson (Talk | contribs) (Category goes at the top. Don't use those old categories please.)

Jump to: navigation, search

This tutorial still refers to the older wxWidgets release 2.6.2 because there are some issues compiling Code::Blocks with the recently released version 2.6.3. Nevertheless you can use these instructions for installing the current version in order to develop applications.

These are the instructions for compiling wxWidgets for use with Code::Blocks. They are primarily intended in preparation for compiling Code::Blocks itself but (hopefully) may also help installing wxWidgets for general development using that framework.

Although these instructions are targeted at the Windows operating system, it should be possible to apply them with slight adjustments to other platforms, since we make use of MinGW.

Installing MinGW

If you have installed the Code::Blocks and MinGW bundle, or already installed MinGW on your own, you can skip this section.

Grab the latest MinGW files from the MinGW download site and install them into a directory of your choice.

NOTE: In these instructions we call the MinGW directory <MINGW>, therefore you have to replace it with your corresponding directory.

NOTE: The files are compressed tarballs. You may need a third-party extraction utility like 7-Zip in order to extract them.

You need at least the following files:

After successful installation of the above, make sure you have the following directories included in your PATH environment variable:

  • <MINGW>\bin;
  • <MINGW>\mingw32\bin;

(You can add them by right-clicking the My Computer icon on your desktop and selecting Properties. Then select the Advanced tab and choose Environment Variables.)

Installing the wxWidgets source code

The wxWidgets 2.6.2 distribution can be found at the wxWidgets download site. (Note that there is also a winhelp file available.) You can choose between an installer and a zip file. You can just get the zip file because the installer is also a zipped version.

If you use the plain zip version, make sure to unzip using the full path. Otherwise the directories won't be created correctly.

NOTE: For the remainder of these instructions we call the wxWidgets directory <WXWIN>. You have to change it to your corresponding directory (e.g. "c:\wxWidgets-2.6.2").

NOTE: You do not need MSYS. Furthermore, you cannot have MSYS in your path, or the wxWidgets compilation will fail. Thus, if you have MSYS installed, ensure that <MSYS>\bin is not in your path before compiling wxWidgets. wxWidgets must be compiled from a "regular" command line (like cmd.exe), not from a Unix-like shell. The same problem could arise if Cygwin is in the path.

Checking make version

If you didn't install MinGW yourself you have to ensure you are using a recent enough version of the make utility. Open a command prompt and type:

mingw32-make -v

The version should read 3.80 or greater, else you need to install a newer version.

Building wxWidgets

Now it is time to compile wxWidgets, open the command promt and change to the wxWidgets directory:

cd <WXWIN>\build\msw

NOTE: The following instructions do not work with MSYS, or other forms of Unix on Windows.

NOTE: You can safely ignore warnings like warning: type attributes are honored only at type definition, which are caused by the makefile turning all warnings (gcc's -Wall) on.

Now the first thing to do is to clean up the source:

mingw32-make -f makefile.gcc BUILD=release MONOLITHIC=1 SHARED=1 UNICODE=1 clean

NOTE: Make sure you use exactly the same options for this step and for the build step below. The clean target uses these variables and only cleans the specified version of the generated object and library files (so it will actually not clean the intended files if these variables are not identical).

NOTE: If you still have problems with compiling after cleaning, you could try to manually remove the gcc_msw directory under the build\msw directory. This directory is the place where the object files are stored.

When everything is clean you can start actually compiling wxWidgets:

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

NOTE: These options are the officially supported Code::Blocks options. If you want another version of wxWidgets (debug or non-unicode) you still have to make sure you build a MONOLITHIC version (one big DLL) for linking Code::Blocks against.

NOTE: If you wish to compile wxWidgets for developing purposes, you may want to change the build options accordingly (e.g. SHARED=0 for a statically linked library, MONOLITHIC=0 for being able to pick only the libraries you really need etc.). See also INSTALL-MSW.txt in your <WXWIN> directory.

Now you can get a cup of coffee or do something else because this step takes some time. Make sure there was no compilation error before you continue.

Copying libraries

After compilation is finished it is useful to copy the resulting libraries to another directory. By doing this you can make several different builds (e.g. debug and release).

  • First create a directory you would like to store the files in. (This could be done in <WXWIN>\lib.)
  • Then go to the directory <WXWIN>\lib\gcc_dll. The directory could be called diffrent depending on your build options (e.g. <WXWIN>\lib\gcc_lib for a static build).
  • Now move all the files (ending in .a and .dll) and the directory msw to the directory of your choice. (This could be <WXWIN>\lib\codeblocks.)

NOTE: Make sure you moved everything out of <WXWIN>\lib\gcc_dll, otherwise you could get into trouble when compiling another version.

Compiling Code::Blocks

Setting up paths

Before finally compiling Code::Blocks itself, you need to setup the paths:

  • Open the Code::Blocks project (CodeBlocks.cbp).
  • It will ask you to define a Global variable
  • Set the path to where you have wxWidgets installed (e.g. "c:\wxWidgets-2.6.2").
  • Compile Code::Blocks.

Post compilation steps

When the compilation process is finished, simply run the update.bat script. It will ensure that all resource files Code::Blocks uses are in the right place and up to date.

NOTE: This step requires an appropriate zip command, which you likely already got. However, in case not, you should find something suitable here.

Building wxWidgets 2.6.2 using VC++ Toolkit 2003

I'll just throw in my notes on the process for both compiler versions as getting VC++ toolkit to work is quite a pain. Code::Blocks needs a couple of changes to support wxWidgets with the VC++ toolkit seamlessly.

install VCToolkitSetup.exe
install PlatformSDK
install .NET Framework SDK Version 1.1
run PlatformSDK->Run all Windows XP 32-bit Build Environment (Retail) batch files (find them in PlatformSDK\Setup)
C:\Program Files\Microsoft Visual C++ Toolkit 2003\Vc7\bin\vcvars32.bat (not needed)

The following environment vars must be set/modified/added via 'Control Panel | System | Advanced | Environment Variables'.

set DOTNETSDK=C:\Program Files\Microsoft.NET\SDK\v1.1 (not needed)
set MSVC=C:\Program Files\Microsoft Visual C++ Toolkit 2003
set MSSDK=C:\Program Files\Microsoft Platform SDK
set VC7=C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7
set INCLUDE=%MSVC%\include;%MSSDK%\include
set LIB=%MSVC%\lib;%MSSDK%\lib;%VC7%\lib
set PATH=%MSVC%\bin;%MSSDK%\bin;%PATH%
set PATH=%PATH%;%MSSDK%\bin\Win64

cd <WXWIN>\build\msw
nmake -f USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode clean
nmake -f USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 CFG=NonUnicode

cd <WXWIN>\lib; move vc_dll codeblocks_vc


project->build options
	directories->resource compiler
	compiler->compiler flags
		enable c++ exception handling (or other options: /GX [same as /EHsc])
	compiler->other options
		delete -D__GNUWIN32__
	linker->link libraries
		delete ctl3d32

compile->compiler options
	programs->additional paths
-OR- copy C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw26_vc_custom.dll
     to application exe directory or c:\windows\system32
-OR- change project->properties->targets->execution working dir
     to C:\wxWidgets-2.6.2\lib\codeblocks_vc (not recommended)

compile->compiler options
	programs->additional paths
		C:\Program Files\Microsoft Platform SDK\Bin
		add C:\Program Files\Microsoft Platform SDK\Include		
		add C:\Program Files\Microsoft Platform SDK\Lib

copy C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw26.exp
     to C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw.exp
copy C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw26.lib
     to C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw.lib
copy C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw26_stc.exp
     to C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw_stc.exp
copy C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw26_stc.lib
     to C:\wxWidgets-2.6.2\lib\codeblocks_vc\wxmsw_stc.lib


building from the commandline (wxwidgets demos)
nmake -f SHARED=1 MONOLITHIC=1 BUILD=release