Installing Code::Blocks from source on Windows
The build process described on this page is a kind of "Self-Hosting." You use an existing version of Code::Blocks to compile the next version. When that version is proven to function correctly it is used to compile the next, and so on.
A properly working Code::Blocks is required to compile the next SVN version. A: Nightly Build is a good candidate to use. It will be paired with a MinGW compiler in the next item.
At the present time, Code::Blocks only compiles successfully with a GCC Compiler on Windows. You will need a complete, working: MinGW installation.
ZIP and SVN functions are not required to run Code::Blocks but ZIP is required to build it and a SVN client is strongly recommended but not absolutely necessary.
You will need a command-line zip.exe program. The recommended one can be found on the: Development Tools page. You do not need WinZip.
Make sure zip.exe is in your PATH as it is used both during the compilation in your current version of Code::Blocks and also by the update.bat script.
You can either download the Code::Blocks source from: http://sourceforge.net/p/codeblocks/code ➡ "Download Snapshot" or use an SVN Client to checkout the code.
It is recommended that you install TortoiseSVN on your machine if you would like an all-in-one SVN solution. TortoiseSVN includes optional command-line client tools, which you should install as they provide a command-line SVN client. Choosing to install the command-line client tools will automatically add them to your PATH. However, if you do not wish to have the TortoiseSVN Explorer extensions in your right-click context menu or just don't feel a need for a graphical client in particular then you can use another: SVN command-line client equally well. Just make sure that whichever client you install has its executable in your PATH.
The autorevision tool which is used during the build of Code::Blocks makes use of the svn.exe binary if it is available (in your PATH) and also uses the SVN meta-data generated by a SVN checkout. If you have both a SVN command-line client in your PATH, and the meta-data, the resulting build of Code::Blocks will show the revision on the loading splash window, the Start here page, and in the About dialog (shown here in the About dialog, indicated by the red arrow):
wxWidgets is the windowing system that Code::Blocks is built on top of. It provides the basic user interface whose components are then weaved together into a complete Integrated Development Environment.
For information about wxWidgets, see their official site: wxWidgets.org
Code::Blocks comes in two wxWidgets versions at this time. There is the more tested and bug free wxWidgets 2.8.12 project and an alternative wxWidgets 3.0.x project which isn't as well tested and also has a 64-bit variation available.
Download the wxWidgets version that you wish to build Code::Blocks against. Minor differences in the building steps will be addressed as needed.
- wxWidgets 2.8.12
- wxWidgets 3.0.2
For specific versions used by the nightly builds, see: [/index.php?topic=3299.0 Important changes to the nightly builds]
You do not need MSYS (in fact, if you have MSYS, make sure it is not in your PATH when building wxWidgets).
Finally, you will need the Code::Blocks sources.
If you prefer a graphical SVN client you can use TortoiseSVN - make a directory where you want to store the sources, right-click on the directory, and select "SVN Checkout," and as shown you will get a checkout dialog:
In the URL of the repository box, enter svn://svn.code.sf.net/p/codeblocks/code/trunk and verify the checkout directory is where you would like it to be. The example given here is "C:\cb_svn" - once satisfied with the arguments click the OK button to process the checkout.
If you do not wish to use a graphical SVN client then a command-line equivalent to the above is to use the svn command - open a command prompt, make a directory, change into that directory, and then checkout a copy of the repository:
mkdir codeblocks-head cd codeblocks-head svn checkout svn://svn.code.sf.net/p/codeblocks/code/trunk
Build wxWidgets Support Library
Depending on which wxWidgets you're using, follow the appropriate section.
Unpack the zip file to a directory of your choice, open a command-line prompt, and navigate to the folder build/msw inside either wxWidgets directory. In this folder is a text file named config.gcc which you can edit with notepad to control the build options. There are two lines to note, CFLAGS ?= and CXXFLAGS ?=. The options given here will go in either or both of those lines.
If your linker runs out of memory while building use:
If your compiler errors out, usually referencing monotree.dll or similar:
To silence warnings that can significantly slow down the compilation process:
All of these options apply to both CFLAGS and CXXFLAGS so the two lines containing all the options would look like this:
CFLAGS ?= -fno-keep-inline-dllexport -D_WIN32_IE=0x0603 -Wno-unused-local-typedefs -Wno-deprecated-declarations
CXXFLAGS ?= -fno-keep-inline-dllexport -D_WIN32_IE=0x0603 -Wno-unused-local-typedefs -Wno-deprecated-declarations
wxWidgets 2.8.12 will not compile by default with a 64-bit compiler. To make it compile with one add CFG=64 to the build line that is given a bit later. However, there is no point to it. The Code::Blocks project files do not have a 64-bit project that targets wxWidgets 2.8.12. To attempt to modify them so they do is beyond the scope of this guide.
As with wxWidgets 2.8.12, if your linker is running out of memory then use -fno-keep-inline-dllexport. In addition, you need -std=gnu++11 in CXXFLAGS. So, in config.gcc your options would look similar to these:
CFLAGS ?= -fno-keep-inline-dllexport
CXXFLAGS ?= -std=gnu++11 -fno-keep-inline-dllexport
wxWidgets 3.0.2 will compile with a 64-bit compiler. You can also specify the CFG=64 build option but the 64-bit Code::Blocks projects do not expect that and are not configured for the naming differences it causes. You can modify the Code::Blocks wx30_64 project, but you don't need to. Just compile with a 64-bit compiler and don't specify the CFG option.
Build wxWidgets Library
At a command-line, inside the build/msw directory, use the following commands to build wxWidgets:
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 clean mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1
If your compiler toolchain is not in your PATH, it should be on a development machine, then put it in your path first:
Where "X" is the drive letter, and "\path\to\toolchain" is where your root toolchain is located.
If your compilation fails for any reason then make sure to run the clean line before trying again.
- If you want to use wxWidgets not only for building Code::Blocks, but also for writing wxWidgets programs, and if you want to use the debugger in those programs, you have to compile a debug build of wxWidgets as well. Use the same commands as for the release build, but replace "release" with "debug".
- Advanced: To reduce the size of your wxWidgets library, you can disable features which are not used by Code::Blocks. However, you should not do this unless you know what you are doing. You have to delete the generated setup.h from lib/gcc_dll/msw/wx before building, because your changes to include/wx/msw will otherwise not be honored.
All the preparation work is now complete and we can actually perform a self-hosting compile of the next Code::Blocks with our current one. If you do not make any changes to your non-Code::Blocks prepared items, like your MinGW compiler version, and the wxWidgets library, then when building subsequent SVN versions of Code::Blocks you can keep all the preparation from a previous build and start with this section. When restarting from this point you can refresh your current Code::Blocks local source with TortoiseSVN. Right-click on your local source directory, go to "TortoiseSVN" in the context-menu, then choose "update to revision." The "head" is always the latest version. If you are using a command-line SVN, just run svn update in the root of your local source directory.
The following instructions are given for the mainstream "wxWidgets 2.8.12 32-bit" version of Code::Blocks. If you are building the wxWidgets 3.0.x or the wxWidgets 3.0.x 64-bit projects then just substitute the appropriate names for the projects, variable directories you are prompted for, update.bat script, and contributor workspace names. Which files you need to open are very clearly labeled in the Code::Blocks source directory.
Open the project file CodeBlocks.cbp.
- You will be prompted to define the global variable $(#wx). In the base field, enter the root of the location where you unpacked wxWidgets.
- You will also be prompted to enter the global variable cb_release_type. Here you can add compiler optimization or debug-flags. Enter -g in the base field as a default or any other options you require for your specific needs.
Prevent unnecessary warnings
The wxWidgets library contains many stubs that are not really used. These will generate an excessive amount of warnings during the compilation of your Code::Blocks project and can significantly impact the time it takes to compile both the main project and the contributors workspace as each warning has to be printed to the build logs. To silence these warnings, go to Compiler Settings:
And under the "Compiler settings" tab (red arrow), "Other compiler options" sub-tab (green arrow), enter "-Wno-unused-local-typedefs" (blue arrow), and you may also add "-Wno-deprecated-declarations" on its own line here too. If you are building using wxWidgets 3.0.x and you compiled that with the "-std=gnu++11" option then you also need to specify that here as well on its own line:
Make sure that "All" is selected as the target (blue arrow), and then click the Build icon (red arrow).
If everything builds correctly your build messages should end with no errors.
Copy wxWidgets support DLL
After the compilation has finished, copy lib\gcc_dll\wxmsw28u_gcc_custom.dll from the wxWidgets directory to the devel directory in the Code::Blocks src directory. If you are working with a wxWidgets 3.0.x build then in the wxWidgets lib\gcc_dll\ directory there will be two .dll files. Copy both of them in that case.
The devel directory is created by compiling the Code::Blocks project in Code::Blocks.
Generate Production Output
Run update.bat (located in the src directory). This will pack the resource files and copy the executables, libraries, and plugins to the output directory. It will also create the output directory if it does not exist.
The stripped ("production") executable is found in output directory together with all libraries and data files. If you want a version with debug symbols instead (caution: huge size!), use the one found in the devel directory.
Compile contributed (or your own) plugins
The workspace file ContribPlugins.workspace contains the project files for all contributed plugins. Open that workspace and compile the plugins which you would like to use (or select "Build workspace" from the Build menu if you want them all).
The NassiShneiderman plugin has a dependency on the Boost library. If you do not wish to use that plugin and therefore not need the library, just right-click on that plugin and choose "close project."
When you open the contrib plugins workspace, you may be asked to define the $(#cb) global compiler variable. This is the path that contains the sdk directory, normally this is the src directory. The build process uses this information to place the plugins and data files into the correct place. Enter the location of the Code::Blocks sources in the same way as for the $(#wx) variable earlier.
Don't forget to run update.bat again after building the contributed plugins.
Copy or move the output directory to where you want Code::Blocks to reside. You probably want to rename the output directory to something else. You can also optionally right-click on codeblocks.exe and choose "create shortcut" and then rename that shortcut to your liking and move it to another location such as your desktop for easy access.