CodeBlocks Setup Guide

From WxWiki
Jump to navigation Jump to search

Code::Blocks Wiki

Code::Blocks' wiki has a good guide on setting up wxWidgets on Code::Blocks:

Code::Blocks Installation in Windows

This page describes the steps I took in order to get Code::Blocks working with a homemade wxWidgets. I used the Code::Blocks+MINGW 1.0 bundle and wxWidgets 2.6.

NOTE: This guide is for compiling with MINGW, not Cygwin nor MSYS.

Preparing Code::Blocks

Building wxWidgets from the command line

Downloading the last stable wxWidgets library

The last stable wxWidgets distribution can be found at the wxWidgets website ( 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 full paths. Otherwise the directories won't be created correctly.

NOTE: In the rest of these instructions I'll be calling the wxWidgets directory %WXWIN% you have to change it to your own directory. (e.g. "c:\wxWidgets-x.x")

Building your own wxWidgets library

Before anything, add the bin directory of MinGW under the CodeBlocks installation directory to the %PATH% variable (Windows, Mac). Now it is time to compile wxWidgets, open the command promt and change to the wxWidgets directory:

 cd %WXWIN%\build\msw

Now we are on the right place we are first going to clean up the source:

 mingw32-make.exe -f makefile.gcc clean 

NOTE: if you still have problems with compiling after cleaning, you may want to remove the directory in the build\msw directory. (it contains object files...) When everything is clean we can compile wxWidgets:

First we have to configure the build. If your makefile.gcc (in my version on line 7) includes config.gcc, your command line parameters will be overriden by the config-file. Thus edit the compiler settings in config.gcc to reflect your choice. The following are recommended: USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0

Otherwise, you can build wxWidgets from the commandline as follows:

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

Now you can get a cup of coffee, or do something else, because this could take a long time.

NOTE: If you mess up and want to clean, you have to pass the same parameters to make clean.

Example for clean commandline:

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

So now everything is compiled for using codeblocks.

Copying libraries

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

  • So first we create a directory this could be done in %WXWIN%\lib.
  • Then we go to the directory %WXWIN%\lib\gcc_dll (could called diffrent when you changed the build options)
  • Rename the directory %WXWIN%\lib\gcc_dll to the directory of your choice. (For me it is %WXWIN%\lib\gcc_dllNonUnicode)

NOTE: Make sure everything is removed from the directory %WXWIN%\lib\gcc_dll else you can get trouble when compiling another version.

Setting Up Code::Blocks

Compiler/Linker Options

Next you should set up Code::Blocks to use the wx-config compiler and linker arguments. The easiest way to do this is to create new compiler flags, which can be turned on or off as needed later on.

Create a wxWidgets Compiler Flag

  1. Go to Project --> Build Options
  2. Under Compiler flags --> General, right-click an item and select "New flag..." from the shortcut menu.
  3. For the Name field, enter something like, "wxWidgets -- Compiler Suggested Settings".
  4. For the Compiler flags field, enter
    `wx-config --cxxflags`
  5. Press OK

Create a wxWidgets Linker Flag

  1. Under Compiler flags --> General, right-clicking an item and select "New flag..." from the shortcut menu.
  2. For the Name field, enter something like, "wxWidgets -- Linker Suggested Settings".
  3. For the Linker flags field, enter
    `wx-config --libs`
  4. Press OK

Now that you have setup the compiler/linker flags, make sure to turn them on under Project --> Build Options --> YourProjectName for wxWidgets projects you wish to build.

Congratulations! You can start developing in wxWidgets. If any problem occurs, just ask at the Code::Blocks forum (