4.  Building CodeBlocks from sources

 4.1  Introduction
  4.1.1  WIN32
  4.1.2  Initial Build System
  4.1.3  Version Control System
  4.1.4  wxWidgets
  4.1.5  Zip
  4.1.6  Building Codeblocks
  4.1.7  WIN32
  4.1.8  LINUX
  4.1.9  Generate a plugins
  4.1.10  Linux
  4.1.11  Contributed Plugins
  4.1.12  Building CodeBlocks

4.1.  Introduction

This article will describe the process used in creating the nightly builds, and can be used as a guideline if you want to build CodeBlocks yourself. It is described as a sequence of actions.

In order to perform our build tasks, we will need several tools. Let’s create an ingredient list for our cooking experiments

4.1.1.  WIN32

Since the CodeBlocks developers build CodeBlocks using GCC, we might as well use that one under windows. The easiest and cleanest port is MinGW. This is the compiler distributed with CodeBlocks when you download the official package. We will stick to version 3.4.5, which works nicely.

First, a brief explanation of MinGW components:

gcc-core
the core of the GCC suite
gcc-g++
the c++ compiler
mingw Runtime
implementation of the run time libraries
mingw utils
several utilities (implementation of smaller programs that GCC itself uses)
win32Api
the APIs for creating Windows programs
binutils
several utilities used in build environments
make
the Gnu make program, so you can build from make files
GDB
the Gnu debugger

I would suggest extracting (and installing for the GDB) everything in the C:\MinGW directory. The remainder of this article will assume that this is where you have put it. If you already have an installation of CodeBlocks that came bundled with MinGW, I still advise you to install MinGW as described here. A compiler does not belong under the directory tree of an IDE; they are two separate things. CodeBlocks just brings it along in the official versions so that the average user does not need to bother with this process.

You may need to add the bin directory of your MinGW installation to your path. An easy way to do this is with the following command at the command prompt:

  set path=%PATH%;C:\MinGW\bin;C:\MinGW\mingw32\bin;

4.1.2.  Initial Build System

For [?] a project description CodeBlocks.cbp is available. If you load this project file in CodeBlocks then you are able to build CodeBlocks from sources. All we need to do is get hold of a pre-built version CodeBlocks.

First, download a nightly build. You can make your selection from here. The nightly builds are unicode versions, containing the core and contributed plug-ins.

Next, unpack the 7-zip file to any directory you like. If you don’t have 7-zip, you can download it for free from [?].

Now, CodeBlocks needs one more dll to work correctly: the WxWidgets dll. You can also download it at the nightly builds forum. Just unzip it into the same directory that you unpacked the CodeBlocks nightly build. It also needs the mingwm10.dll. It’s in the bin directory of our MinGW installation. So, it’s important to make sure the bin directory of your MinGW installation is in your path variable.

Finally, start up this new nightly build of CodeBlocks. It should discover the MinGW compiler we just installed.

4.1.3.  Version Control System

In order to be able to retrieve the latest and greatest CodeBlocks sources, we need to install a Version Control System.

The CodeBlocks developers provide their sources through the version control system[?]. So, we need a client to access their svn repository of sources. A nice, easy client for Windows is [?], which is freely available. Download and install it, keeping all suggested settings.

Now, go create a directory wherever you like, for example D:\projects\CodeBlocks. Right click on that directory and choose from the pop-up menu: svn-checkout. In the dialog that pops up, fill in the following information for Url of Repository: svn://svn.berlios.de/codeblocks/trunk

and leave all other settings as they are.

Now be patient while TortoiseSVN retrieves the most recent source files from the CodeBlocks repository into our local directory. Yes; all those CodeBlocks sources are coming your way!

For more info on SVN settings, see info on SVN settings. If you don’t like an Explorer integration or look for a cross-plattform client you might want to have a look at RapidSVN..

4.1.4.  wxWidgets

[?] is a platform abstraction that provides an API to support many things such as GUI, sockets, files, registry functionality. By using this API, you can create a platform independent program.

CodeBlocks is a wxWidgets (here after: wx) application, that means if you want to run CodeBlocks you needed the wx functionality. This can be provided in a couple of ways. It could be a .dll or a static library. CodeBlocks uses wx as a dll and this dll can also be downloaded from the nightly build section of the forum.

However, if we want to build a wx application, we need to include the headers of the wx sources. They tell the compiler about the functionality of wx. In addition to those header files, our application needs to link to the wx import libraries. Well, let’s take it step by step.

Wx is provided as a zip file of it’s sources, so we need to build that ourselves. We already shopped for the MinGW compiler, so we have all the tools we need at hand.

Next, let’s unzip the wx sources into C:\Projects so we will end up with a wx root directory like this: C:\Projects\wxWidgets-2.8.7. Next unzip the patch into the same directory letting it overwrite files. Note that we are going to refer to the wx root directory from now on as <wxDir>

Now, we are going to build the wxWidgets. This is how we do it:

First, make sure C:\MingGW\bin is in your path, during the build some programs will be called that reside in the the MinGW\bin directory. Also, Make has to be version 3.80 or above.

Now it is time to compile wxWidgets. Open the command prompt and change to the wxWidgets directory:

  cd <wxDir>\build\msw

We are now in the right place. We are first going to clean up the source:

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

Once everything is clean, we can compile wxWidgets:

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

This is going to take some time.

For making the debug build, follow these steps:

Well have a little look in the directory (<wxDir>\lib\gcc_dll) now. The import libraries and the dll have shown up and there should also a mswu\wx subdirectory at that position containing setup.h.

Congratulations! You have just built wxWidgets!

Let’s do some more preliminary tasks before we get to the real deal of compiling CodeBlocks.

4.1.5.  Zip

During the build of CodeBlocks, several resources are going to be zipped in zip files. Therefore, the build process should have access to a zip.exe. We have to download that zip.exe and put it somewhere in our path. A good place is: MingW\bin.

You can download zip.exe for free from this site and this is a direct link(32bit) to the most recent version at the time of this writing.

Once downloaded, simply extract zip.exe to the appropriate location.

4.1.6.  Building Codeblocks

win32
Starting update_revision.bat
linux
Starting update_revision.sh

With this function the SUN revision of the Nightly Builts is updated in the sources. The file can be found in the main directory of the CodeBlocks sources.

4.1.7.  WIN32

Now, open the project CodeBlocks.cbp in CodeBlocks. Generate CodeBlocks by starting the build process. After the creation of CodeBlocks, the generated files with the debug information can be found in the devel subdirectory. By calling the batch file update.bat from the source directory, the files are copied to the output subdirectory and the debug information is stripped.

4.1.8.  LINUX

When generating under Linux, the following steps are necessary. In this example we assume that you are in the CodeBlocks source directory. Under Linux, the environment variable PKG_CONFIG_PATH must be set. The <prefix> directory has to contain the codeblocks.pc file.

  PKG_CONFIG_PATH=$PKG_CONFIG_PATH:<prefix>

  sh update_revsion.sh
  ./bootstrap
  ./configure --with-contrib=[all | plugin names separated with comma] --prefix=<install-dir>
  make
  make install (root)

4.1.9.  Generate a plugins

Afterwards, configure the global variables via ’Settings’ /’Global Variables’ .

Variable cb

For the cb variable, set the base entry to the source directory of CodeBlocks.

  <prefix>/codeblocks/src

Variable wx

For the wx variable, set the base entry to the source directory of wx (e.g.

  C:\Programme\wxWidgets-2.8.7

In the CodeBlocks project, the project variable WX_SUFFIX is set to u. This means that, when generating CodeBlocks linking will be carried out against the *u_gcc_custom.dll library. The official nightly Builts of CodeBlocks will be linked against gcc_cb.dll. In doing so, the layout is as follows.

  gcc_<VENDOR>.dll

The <VENDOR> variable is set in the configuration file compiler.gcc. To ensure, that a distinction is possible between the officially generated CodeBlocks and those generated by yourself, the default setting VENDOR=custom should never be changed.

Afterwards create the workspace ContribPlugins.cbp via ’Project’ /’Build workspace’ . Then execute update.bat once more.

4.1.10.  Linux

Variable wx bei globalen Variablen konfigurieren. Configure the wx variable with the global variables.

base
/usr
include
/usr/include/wx-2.8
lib
/usr/lib

debug CodeBlocks. Start CodeBlocks in the output directory and load CodeBlocks.cbp as the project. Then set the breakpoint and start with ’Debug and Run’ (f8).

4.1.11.  Contributed Plugins

This brings us to the last preliminary task. The CodeBlocks code can be divided into 2 major parts: the core with internal plug-ins, and the contributed plug-ins. You always need to build the core/internal parts before building the contrib part.

To build the internal part, you can use the CodeBlocks project file which you can find at: <cbDir>\src\CodeBlocks.cbp. Our CodeBlocks master directory is from now one mentioned as <cbDir>, by the way. A workspace is something that groups several projects together. To build the contrib plug-ins, they can be found at

  <cbDir>\src\ContribPlugins.workspace

But, let’s create a worksapce containing everything. Let’s put that workspace in the master directory <cbDir>. Just use a regular text editor and create a file with the name CbProjects.workspace and give it the following content :

  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  <CodeBlocks_workspace_file>
   <Workspace title="All contrib plugins">
   <Project filename="plugins\contrib\AutoVersioning\AutoVersioning.cbp" active="1" />
   <Project filename="plugins\contrib\byogames\byogames.cbp" />
   <Project filename="plugins\contrib\cb_koders\cb_koders.cbp" />
   <Project filename="plugins\contrib\codesnippets\codesnippets.cbp" />
   <Project filename="plugins\contrib\codestat\codestat.cbp" />
   <Project filename="plugins\contrib\copystrings\copystrings.cbp" />
   <Project filename="plugins\contrib\devpak_plugin\DevPakPlugin.cbp" />
   <Project filename="plugins\contrib\dragscroll\dragscroll.cbp" />
   <Project filename="plugins\contrib\envvars\envvars.cbp" />
   <Project filename="plugins\contrib\help_plugin\help-plugin.cbp" />
   <Project filename="plugins\contrib\keybinder\keybinder.cbp" />
   <Project filename="plugins\contrib\lib_finder\lib_finder.cbp" />
   <Project filename="plugins\contrib\profiler\cbprofiler.cbp" />
   <Project filename="plugins\contrib\regex_testbed\RegExTestbed.cbp" />
   <Project filename="plugins\contrib\source_exporter\Exporter.cbp" />
   <Project filename="plugins\contrib\symtab\symtab.cbp" />
   <Project filename="plugins\contrib\ThreadSearch\ThreadSearch.cbp" />
   <Project filename="plugins\contrib\wxSmith\wxSmith.cbp" />
   <Project filename="plugins\contrib\wxSmithContribItems\wxSmithContribItems.cbp" />
   <Project filename="tools\cb_share_config\cb_share_config.cbp" />
   </Workspace>
  </CodeBlocks_workspace_file>

We will use this workspace to build all of CodeBlocks.

4.1.12.  Building CodeBlocks

Finally we have arrived at the final step; our final goal. Run the CodeBlocks executable from your nightly build download. Choose Open from the File menu and browse for our above created workspace, and open it up. Be a little patient while CodeBlocks is parsing everything, and CodeBlocks will ask us for 2 global variables, these global variables will tell the nightly CodeBlocks where it can find wxWidgets (remember : header files and import libraries) and where it can find .... CodeBlocks, this is needed for the contrib plug-ins, they need to know (as for any user created plug-in) where the sdk (CodeBlocks header files) are. These are the values in our case :

wx
<wxDir> base directory of wxWidgets.
cb
<cbDir>/src CodeBlocks directory contaning the sources.

Now go to the Project Menu and choose (re)build workspace, and off you go. Watch how CodeBlocks is building CodeBlocks.

Once the build is complete, open up a console in <cbDir>/src and run the command update.bat. This will transfer all built deliverables from <cbDir>/src/devel to <cbDir>/src/output. In addition, it will strip out all debugging symbols. This step is very important - never ever forget it.

Now you can copy the wx dll in both that output and the devel directory.

Then you can close CodeBlocks. That was the downloaded nightly remember?

Time to test it. In the output directory, start up the CodeBlocks.exe. If everything went well, you’ll have your very own home-built CodeBlocks running.