Difference between revisions of "Installing Code::Blocks from source on Windows"

From Code::Blocks
Line 62: Line 62:
 
You do ''not'' need MSYS (''in fact, if you have MSYS, make sure it is not in your PATH when building wxWidgets'').
 
You do ''not'' need MSYS (''in fact, if you have MSYS, make sure it is not in your PATH when building wxWidgets'').
  
=== Code::Blocks sources ===
+
=== Code::Blocks Sources ===
  
 
Finally, you will need the Code::Blocks sources.  
 
Finally, you will need the Code::Blocks sources.  

Revision as of 23:41, 23 December 2015

Overview

Self-Hosting

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.

Prerequisites

Bootstrap Code::Blocks

A properly working Code::Blocks is required to compile the next SVN version. A [/index.php?board=20.0 Nightly Build] is a good candidate to use. It will be paired with a MinGW compiler in the next section.

MinGW Compiler

At the present time, Code::Blocks only compiles successfully with the MinGW compiler (or any other gcc for that matter). You will need a complete, working MinGW installation or TDM-MinGW package.

Do not use the barebones MinGW with GCC 4.5.1 as you'll run (with this specific version) into a linker bug (which happened to me on Vista SP1 32-bit on 2011-02-28); the solution is to use the TDM-GCC 4.5.1 package, or later.

Utilities

ZIP and SVN functions are not required to run Code::Blocks but are necessary to build it.

ZIP

You'll also need a working 'zip' program. If you have the version listed on our tools page, you'll be fine.

The zip program coming with cygwin will not work properly. You do not need WinZip.

Make sure the zip binary is in your PATH so the update.bat script will be able to find it (alternatively, you can edit the batch file, setting the ZIPCMD variable to something else).

The easiest way is to put zip.exe into bin inside your MinGW installation directory (that folder is normally in the path).

SVN

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.

For convenience, it is recommended that you install TortoiseSVN on your machine, as this is a lot more comfortable. TortoiseSVN includes an optional command-line SVN client and the option to add it to your PATH during installation. 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 GUI in particular then you can use a SVN command-line client equally well. If you choose to install the optional SVN command-line client that is part of TortoiseSVN and add it to your PATH then you do not need any other SVN executable.

It is generally a good idea to install a command-line client (and adding it to your PATH) even if you use the TortoiseSVN GUI for convenience. The autorevision tool which is used during the build of Code::Blocks makes use of the svn binary if it is available. This is preferable to the manual parsing of the entries file that is used as a fall-back. As a result of having a SVN command-line client in your path during the build process 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 arrow):

About SVN10627.png

wxWidgets

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.

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).

Code::Blocks Sources

Finally, you will need the Code::Blocks sources.

TortoiseSVN

If you prefer a GUI 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:

Tor SVN.png

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.

Command-Line SVN

If you do not wish to use a GUI 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

Unicode Build

Compile wxWidgets in Unicode mode

After unpacking the zip file to a directory of your choice, open a cmd prompt, and navigate to the folder build/msw inside the wxWidgets folder. Use the following commands to compile wxWidgets:

set path=c:\mingw\bin;c:\mingw\mingw32\bin
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

This assumes your MinGW installation is in C:\mingw. Use a different path if you installed MinGW somewhere else.

You will see a lot of warning messages during compilation. Don't worry, this is normal, you are compiling wxWidgets. The build process may take 10-30 minutes, depending on your computer's speed.

If you are using a recent version of MinGW you may find that the object files are too large and that the linker runs out of memory. To fix this problem you need to edit config.gcc so that inline functions are not exported, by modifying the CFLAGS and CXXFLAGS lines to:

 CFLAGS ?= -fno-keep-inline-dllexport
 CXXFLAGS ?= -fno-keep-inline-dllexport

If your compiler errors while compiling wxWidgets 2.8.12 with a more recent MinGW compiler then try these config.gcc build lines:

 CFLAGS ?= -D_WIN32_IE=0x0603 -fno-keep-inline-dllexport
 CXXFLAGS ?= -D_WIN32_IE=0x0603 -fno-keep-inline-dllexport

remark: 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" by "debug".

Optional:

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 honoured.

Compile Code::Blocks

Now, before this step, you have prepared all the stuff to build code::blocks. It's very interesting that we use code::blocks to build code::blocks binaries.

Open project

Open the project file CodeBlocks.cbp.

  • You will be prompted to define the global variable $(#wx). Enter the location where you unpacked wxWidgets.

Global variable.png

Global variable2.png


  • 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.

Compile project

Hit the blue gear and lean back. Compilation may take 3-5 minutes, depending on the speed of your computer.

Win build button.png

Win build target.png

Win build finish.png


Copy wxWidgets support DLL

After the compilation has finished, copy lib\gcc_dll\wxmsw28u_gcc_custom.dll from the wxWidgets directory to the src\devel directory inside the Code::Blocks source folder (it will also work if you keep a copy of that library in your Windows folder or anywhere in your system path, but this is generally not recommended because you can get into dll hell).

Win output folder.png

Win copy dll.png


Runing script file

Run src\update.bat (located in the root source directory). This will pack the resource files and copy libraries and plugins to their correct locations.

Win run bat.png

The stripped ("production") executable is found in output folder 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 folder.
Congratulations, you own a freshly built version of Code::Blocks!

Win final folder.png

Note for future updates

Go to the Code::Blocks root directory and run svn update (or use TurtoiseSVN to the same effect).
Then open and build the project as described before (and any contrib plugins that you wish to use), and re-run src\update.bat.

Install Code::Blocks

Copy the folder output to where you want Code::Blocks to reside.

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 context menu if you want them all).

Contribute plugin.png

When you open the contrib plugins workspace, you will be asked to define the $(#cb) global compiler variable. This is the path that contains the sdk folder normally this is codeblocks\src. 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 contrib plugins.

ANSI Build

DEPRECATION WARNING:

As of February 2006, the official default build for Code::Blocks is Unicode (see above). Although ANSI builds are technically possible, we discourage their use unless there is a good reason.
Support for ANSI builds is likely to be dropped after Version 1.0 is out.

There is hardly any good argument against using a Unicode build if your OS supports Unicode, even if you do not understand any other language than English, as a Unicode version guarantees that it will be able to work with whatever languages you may possibly encounter in the future -- at a very reasonable cost.

However, if you absolutely don't care about Unicode or if you are bound to use Windows 95, then you may want to build an ANSI version nevertheless.

Compile wxWidgets in ANSI mode

After unpacking the zip file to a directory of your choice, open a cmd prompt, and navigate to the folder build/msw inside the wxWidgets folder. Use the following commands to compile wxWidgets

set path=c:\mingw\bin;c:\mingw\mingw32\bin
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 clean
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0

This assumes your MinGW installation is in C:\mingw. Use a different path if you installed MinGW somewhere else.

You will see a lot of warning messages during compilation. Don't worry, this is normal, you are compiling wxWidgets. The build process may take 10-30 minutes, depending on your computer's speed.

Optional:

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 honoured.

Compile Code::Blocks

Open the project CodeBlocks.cbp. You will be prompted to define the global variable $(#wx) if you have not used it before. Enter the location where you unpacked wxWidgets.

Important: The project file is set to compile an Unicode version of Code::Blocks by default. To make an ANSI build, you have to make the following two changes to build options before compiling: 1. In the "Compiler" tab, under "#defines", remove the entry wxUSE_UNICODE. 2. Under "Custom variables", set the variable WX_SUFFIX to empty (default value: u).

Hit the blue gear and lean back. Compilation may take 3-5 minutes, depending on the speed of your computer.

After the compilation has finished, copy wxmsw28u_gcc_custom.dll from lib\gcc_dll inside the wxWidgets directory to the devel directory inside the Code::Blocks source folder (it will also work if you keep a copy of that library in your Windows folder or anywhere in your system path, but this is generally not recommended because you can get into dll hell). Run update.bat (located in the root source directory). This will pack the resource files and copy libraries and plugins to their correct locations. The location of executable is src\output in C::B tree. From here you'll not need the nightly build anymore.

One little note for svn updates and rebuilds : just go into the codeblocks root directory and do svn update (or use Turtoise svn).

Then run the src/output/codeblocks.exe, reload project, build it, reload plugins workspace, build it, quit codeblocks and re-run update.bat. You'll have an up-to-date C::B in 3 minutes !

Install Code::Blocks

Copy the folder output to where you want Code::Blocks to reside.

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 context menu if you want them all). Don't forget to run update.bat again after building the contrib plugins.

Note that the Nassi Shneiderman plugin (part of the contrib plugins) has a dependency on boost which is needed to compile this plugin. Boost does not need to be compiled therefore.