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

From CodeBlocks
Jump to: navigation, search
m (Compile wxWidgets in Unicode mode)
(Code::Blocks Sources: Add a note to skip this part if not needed)
 
(258 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
[[Category:Installing Code::Blocks]]
 
[[Category:Installing Code::Blocks]]
 
[[Category:Installing Code::Blocks from source]]
 
[[Category:Installing Code::Blocks from source]]
== Prerequisites ==
+
== Overview ==
  
=== Note for RC2 users ===
+
=== Self-Hosting ===
  
The older Code::Blocks RC2 does not support global compiler variables which were added after RC2 was released and is unable to read project files generated with post-RC2 versions.
+
The build process described on this page is a kind of "[https://en.wikipedia.org/wiki/Self-hosting 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.
To build Code::Blocks, you need a post-RC2 build, such as ''8.02'' or any of the ''nightly builds'' obtainable by [http://forums.codeblocks.org/index.php?board=20.0 searching the forum].
+
  
=== MinGW compiler ===
+
== Prerequisites ==
  
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 [http://www.tdragon.net/recentgcc/ TDM-MinGW package].
+
=== Bootstrap Code::Blocks ===
  
'''Do not''' use the barebones MinGW with GCC 4.5.1 as you'll run (with this specific version) into [http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43601 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.
+
A properly working Code::Blocks is required to compile the next SVN version.  A: [[Installing_Code::Blocks_nightly_build_on_Windows | Nightly Build]] is a good candidate to use. It will be paired with a MinGW compiler in the next item.
  
=== wxWidgets ===
+
=== MinGW Compiler ===
  
[http://www.wxwidgets.org/ wxWidgets.org]
+
At the present time, Code::Blocks only compiles successfully with a MinGW compiler toolchain on Windows. You will need a complete, working: [[MinGW installation]].
  
Code::Blocks uses
+
=== wxWidgets ===
* since 02 April 2011 wxWidgets 2.8.12 <br/>Download: [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.12.zip wxMSW-2.8.12.zip]
+
  
* since 28 March 2009 wxWidgets 2.8.10 <br/>Download: [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.10.zip wxMSW-2.8.10.zip]
+
wxWidgets is the "[https://en.wikipedia.org/wiki/Graphical_user_interface graphical user interface toolkit]" that Code::Blocks is built on top of.
  
* since 18 October 2008 wxWidgets 2.8.9 <br/>Download: [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.9.zip wxMSW-2.8.9.zip]
+
For information about wxWidgets, see their official site ➡ [http://www.wxwidgets.org/ wxWidgets.org]
  
* since 19 July 2008 wxWidgets 2.8.8 <br/>Download: [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.8.zip wxMSW-2.8.8.zip]
+
Download: [https://github.com/wxWidgets/wxWidgets/releases/download/v2.8.12/wxMSW-2.8.12.zip wxMSW-2.8.12.zip]
  
* since 28 November 2007 wxWidgets 2.8.7 <br/>Download: [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.7.zip wxMSW-2.8.7.zip]
+
=== Utilities ===
  
* since November 2007 wxWidgets 2.8.6 <br/>Download: [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.6.zip wxMSW-2.8.6.zip]
+
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.
  
* since May 2007 wxWidgets 2.8.4<br/>Download: [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.4.zip wxMSW-2.8.4.zip]
+
==== ZIP ====
  
For latest infos check forum: [http://forums.codeblocks.org/index.php?topic=3299.0 Important changes to the nightly builds]
+
You will need a command-line <tt>zip.exe</tt> program. The recommended one can be found on the: [[MinGW installation#Development Tools|Development Tools]] page.  You do ''not'' need WinZip.
  
 +
Make sure <tt>zip.exe</tt> is in your [https://en.wikipedia.org/wiki/PATH_(variable) PATH] as it is used both during the compilation in your current version of Code::Blocks and also by the <tt>update.bat</tt> script.
  
You do ''not'' need MSYS (''in fact, if you have MSYS, make sure it is not in your PATH when building wxWidgets'').
+
==== SVN ====
  
=== SVN client ===
+
It is recommended, but not required, that you install a SVN client. If you are a absolute beginner in programming skip this part and go to [http://wiki.codeblocks.org/index.php/Installing_Code::Blocks_from_source_on_Windows#Code::Blocks_Sources Code::Blocks Sources].  An example would be [http://tortoisesvn.net/downloads TortoiseSVN] 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: [http://subversion.apache.org/packages.html SVN command-line client] equally well.  Just make sure that whichever client you install has its executable in your PATH.
  
In order to check out the Code::Blocks sources you will need a SVN client.
+
The <tt>autorevision</tt> tool which is used during the build of Code::Blocks makes use of the <tt>svn.exe</tt> 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):
For convenience, it is recommended that you install [http://tortoisesvn.net/downloads TortoiseSVN] on your machine, as this is a lot more comfortable. However, if you get a bad feeling when some program is messing with your Explorer menu, then you can use the [http://subversion.tigris.org/project_packages.html svn command-line client] equally well.
+
  
It is generally a good idea to install the command-line client (and adding it to PATH) even if you use TortoiseSVN for convenience. The <tt>autorevision</tt> tool which is used during the build of Code::Blocks makes use of the <tt>svn</tt> binary if it is available. This is preferable to the manual parsing of the entries file that is used as fall-back.
+
[[Image:About_SVN10627.png]]
  
 +
=== Code::Blocks Sources ===
  
Please do note that working copies checked out with the 1.4 version of Subversion are no longer compatible with earlier versions (Subversion will transparently update existing repositories).
+
If you don't wish to use a SVN utility, you can download a snapshot from: http://sourceforge.net/p/codeblocks/code ➡ "Download Snapshot.". Now you can go on to the [http://wiki.codeblocks.org/index.php/Installing_Code::Blocks_from_source_on_Windows#Build_wxWidgets_Support_Library next section]
  
The built-in fall-back mechanism in <tt>autorevision</tt> has been updated to the new 1.4 format and will no longer work with the old format.<br>
+
The last item is to acquire the Code::Blocks source code. Follow the appropriate instructions for whether you have a graphical or command line SVN client.
Therefore, if you use a Subversion client from the 1.0-1.3 line, you ''must'' put the command line tool into <tt>PATH</tt> for a successful build.<br>
+
If you use Subversion 1.4, then it is good practice nevertheless, but you can do without, too.
+
  
=== svn.exe ===
+
==== TortoiseSVN ====
If you want to show the SVN number in your code::blocks dialog box.
+
  
[[Image:Svn number.png|300*300px]]
+
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:
  
You should also let svn.exe exist in the PATH of your windows system.
+
[[Image:Tor_SVN.png]]
A command line SVN package can be download here [http://www.open.collab.net/downloads/subversion/ CollabNet Subversion Command-Line Client v1.6 (for Windows)].
+
  
=== zip.exe ===
+
In the URL of the repository box, enter <tt><nowiki>svn://svn.code.sf.net/p/codeblocks/code/trunk</nowiki></tt> 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.
  
You'll also need a working 'zip' program.
+
==== Command-Line SVN ====
If you have the version listed on our [[MinGW installation#Other developer tools|tools page]], you'll be fine.
+
  
The zip program coming with cygwin will ''not'' work properly. You do ''not'' need WinZip.
+
If you do not wish to use a graphical SVN client then a command-line equivalent to the above is to use the <tt>svn</tt> command - open a command prompt, make a directory, change into that directory, and then checkout a copy of the repository:
 
+
Make sure the zip binary is in your PATH so the <tt>update.bat</tt> 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 <tt>bin</tt> inside your MinGW installation directory (that folder is normally in the path).
+
 
+
=== Code::Blocks sources ===
+
 
+
You will also (obviously) need the Code::Blocks sources.
+
 
+
Using ''TortoiseSVN'', make a folder where you want to store the sources, right-click on the folder, and select "SVN Checkout...".
+
 
+
[[Image:Win svn checkout.png]]
+
 
+
In the top box, enter svn://svn.berlios.de/codeblocks/trunk and hit the OK button.
+
 
+
Using ''svn'', you have to open a command prompt ("DOS Window"). Make a folder, change directory, and run svn:
+
  
 
  mkdir codeblocks-head
 
  mkdir codeblocks-head
 
  cd codeblocks-head
 
  cd codeblocks-head
  svn checkout <nowiki>svn://svn.berlios.de/codeblocks/trunk</nowiki>
+
  svn checkout <nowiki>svn://svn.code.sf.net/p/codeblocks/code/trunk</nowiki>
  
== Unicode Build ==
+
== Build wxWidgets Support Library ==
  
=== Compile wxWidgets in Unicode mode ===
+
=== Configure Build Options ===
  
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:
+
Unpack the wxWidgets zip file to a directory of your choice, open a command-line prompt, and navigate to the directory <tt>build/msw</tt> inside the wxWidgets directory. In this directory there is a text file named <tt>config.gcc</tt> which you can edit with notepad to control the build options.  There are two lines to note, <tt>CFLAGS ?=</tt> and <tt>CXXFLAGS ?=</tt>.  The options given here will go in either or both of those lines.
  
set path=c:\mingw\bin;c:\mingw\mingw32\bin
+
If your linker runs out of memory while building use:
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.
+
-fno-keep-inline-dllexport
  
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.
+
Some versions of the MinGW Windows Runtime Library will cause an error during compilation. See: [https://sourceforge.net/p/tdm-gcc/bugs/269/ Bug #269].  If this is the case with the toolchain you are using then try this workaround:
  
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:
+
-D_WIN32_IE=0x0603
  
  CFLAGS ?= -fno-keep-inline-dllexport
+
To silence warnings that can significantly slow down the compilation process:
  
  CXXFLAGS ?= -fno-keep-inline-dllexport
+
-Wno-unused-local-typedefs
  
 +
and
  
''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.''
+
-Wno-deprecated-declarations
''Use the same commands as for the release build, but replace "release" by "debug".''
+
  
'''Optional:'''
+
All of these options apply to both <tt>CFLAGS</tt> and <tt>CXXFLAGS</tt> so the two lines containing all the options would look like this:
  
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.
+
  CFLAGS ?= -fno-keep-inline-dllexport -D_WIN32_IE=0x0603 -Wno-unused-local-typedefs -Wno-deprecated-declarations
  
=== Compile Code::Blocks ===
+
  CXXFLAGS ?= -fno-keep-inline-dllexport -D_WIN32_IE=0x0603 -Wno-unused-local-typedefs -Wno-deprecated-declarations
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====
+
wxWidgets 2.8.12 will not compile by default with a 64-bit compiler.  To make it compile with one add <tt>CFG=64</tt> to the build line that is given next. This would be useful for your own 64-bit programs but 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.
Open the project file '''CodeBlocks.cbp'''. You will be prompted to define the global variable $(#wx). Enter the location where you unpacked wxWidgets.
+
  
[[Image:Global_variable.png]]
+
=== Build wxWidgets Library ===
  
[[Image:Global_variable2.png]]
+
At a command-line, inside the <tt>build/msw</tt> directory, use the following commands to build wxWidgets:
  
====Compile project====
+
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1  clean
Hit the blue gear and lean back. Compilation may take 3-5 minutes, depending on the speed of your computer.
+
mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1
  
[[Image:Win build button.png]]
+
If your compiler toolchain is not in your PATH, it should be on a development machine, then put it in your path first:
  
[[Image:Win build target.png]]
+
set PATH=X:\path\to\toolchain\bin;%PATH%
  
[[Image:Win build finish.png]]
+
Where "'''''X'''''" is the drive letter, and "'''''\path\to\toolchain\bin'''''" is where your toolchain is located.  
  
 +
If your compilation fails for any reason then make sure to run the ''clean'' line before trying again.
  
====Copy wxWidgets support DLL====
+
== Build Code::Blocks ==
After the compilation has finished, copy <tt>lib\gcc_dll\wxmsw28u_gcc_custom.dll</tt> from the wxWidgets directory to the <tt>src\devel</tt> 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).
+
  
[[Image:Win output folder.png]]
+
=== Self-Hosting ===
  
[[Image:Win copy dll.png]]
+
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 <tt>svn update</tt> in the root of your local source directory.
  
 +
=== Open project ===
 +
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.
  
====Runing script file====
+
*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.
Run <tt>src\update.bat</tt> (located in the root source directory). This will pack the resource files and copy libraries and plugins to their correct locations.
+
  
[[Image:Win run bat.png]]
+
[[Image:Global_Variables.png]]
  
The stripped ("production") executable is found in <tt>output</tt> 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 <tt>devel</tt> folder.<br>
+
[[Image:Global_wx.png]]
Congratulations, you own a freshly built version of Code::Blocks!
+
  
[[Image:Win final folder.png]]
+
=== Prevent unnecessary warnings ===
  
====Note for future updates====
+
Building Code::Blocks against the wxWidgets library will generate an excessive amount of warnings during the compilation. This 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 log. To silence these warnings, go to Compiler Settings:
Go to the Code::Blocks root directory and run <tt>svn update</tt> (or use TurtoiseSVN to the same effect).<br/>
+
Then open and build the project as described before (and any contrib plugins that you wish to use), and re-run <tt>src\update.bat</tt>.
+
  
=== Install Code::Blocks ===
+
[[Image:Compiler_Settings.png]]
  
Copy the folder output to where you want Code::Blocks to reside.
+
And under the "Compiler settings" tab (red arrow), "Other compiler options" sub-tab (green arrow), enter "<tt>-Wno-unused-local-typedefs</tt>" (blue arrow), and you may also add "<tt>-Wno-deprecated-declarations</tt>" on its own line here too.
  
=== Compile contributed (or your own) plugins ===
+
[[Image:Unused_Local_Typedefs.png]]
  
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).<br/>
+
=== Compile project ===
 +
Make sure that "All" is selected as the target (blue arrow), and then click the Build icon (red arrow).
  
[[Image:Contribute plugin.png]]
+
[[Image:Compile_All.png]]
  
When you open the contrib plugins workspace, you will be asked to define the <tt>$(#cb)</tt> 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 <tt>$(#wx)</tt> variable earlier.
+
If everything builds correctly your build messages should end with no errors.
  
Don't forget to run update.bat again after building the contrib plugins.
+
[[Image:Build_Log.png]]
  
== ANSI Build ==
+
=== Copy wxWidgets support DLL ===
 +
After the compilation has finished, copy <tt>lib\gcc_dll\wxmsw28u_gcc_custom.dll</tt> from the wxWidgets directory to the <tt>devel</tt> directory in the Code::Blocks <tt>src</tt> directory.
  
<div style="background-color: #f7d9d9; border: 1px solid #000">
+
[[Image:Update_Devel_Output.png]]
<div style="margin: 5px;">
+
  
==== DEPRECATION WARNING: ====
+
The <tt>devel</tt> directory is created by compiling the Code::Blocks project in Code::Blocks.
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.<br/>
+
''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.
+
=== Generate Production Output ===
 +
Run <tt>update.bat</tt> (located in the <tt>src</tt> directory). This will pack the resource files and copy the executables, libraries, and plugins to the <tt>output</tt> directory.  It will also create the <tt>output</tt> directory if it does not exist.
  
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.
+
[[Image:Update_bat.png]]
  
</div>
+
The stripped ("production") executable is found in <tt>output</tt> 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 <tt>devel</tt> directory.
</div>
+
  
==== Compile wxWidgets in ANSI mode ====
+
[[Image:Update_Output.png]]
  
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
+
=== Compile contributed (or your own) plugins ===
 
+
set path=c:\mingw\bin;c:\mingw\mingw32\bin
+
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=0 clean
+
mingw32-make -f makefile.gcc USE_XRC=1 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 [[wikipedia:DLL Hell|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).
+
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).
  
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 !
+
The NassiShneiderman plugin has a dependency on the "[http://www.boost.org/ 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."
  
==== Install Code::Blocks ====
+
Don't forget to run <tt>update.bat</tt> again after building the contributed plugins.
  
Copy the folder output to where you want Code::Blocks to reside.
+
[[Image:Build_Workspace.png]]
  
==== Compile contributed (or your own) plugins ====
+
== Install Code::Blocks ==
  
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.
+
Copy or move the <tt>output</tt> directory to where you want Code::Blocks to reside. You probably want to rename the <tt>output</tt> directory to something else.  You can also optionally right-click on <tt>codeblocks.exe</tt> 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.
  
Note that the Nassi Shneiderman plugin (part of the contrib plugins) has a dependency on [http://www.boost.org boost] which is needed to compile this plugin. Boost does not need to be compiled therefore.
+
If you want to run Code::Blocks on a machine without your compiler toolchain being in the PATH then you will likely have to include, in the same directory as the <tt>codeblocks.exe</tt> is fine, support .dll files from your compiler toolchain. The easiest way to determine the required files is to not have your compiler toolchain in your PATH and repeatedly run Code::Blocks and copy over each .dll it says is missing until all have been found.

Latest revision as of 22:09, 25 August 2017

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: Nightly Build is a good candidate to use. It will be paired with a MinGW compiler in the next item.

MinGW Compiler

At the present time, Code::Blocks only compiles successfully with a MinGW compiler toolchain on Windows. You will need a complete, working: MinGW installation.

wxWidgets

wxWidgets is the "graphical user interface toolkit" that Code::Blocks is built on top of.

For information about wxWidgets, see their official site ➡ wxWidgets.org

Download: wxMSW-2.8.12.zip

Utilities

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.

ZIP

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.

SVN

It is recommended, but not required, that you install a SVN client. If you are a absolute beginner in programming skip this part and go to Code::Blocks Sources. An example would be TortoiseSVN 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):

About SVN10627.png

Code::Blocks Sources

If you don't wish to use a SVN utility, you can download a snapshot from: http://sourceforge.net/p/codeblocks/code ➡ "Download Snapshot.". Now you can go on to the next section

The last item is to acquire the Code::Blocks source code. Follow the appropriate instructions for whether you have a graphical or command line SVN client.

TortoiseSVN

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:

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

Configure Build Options

Unpack the wxWidgets zip file to a directory of your choice, open a command-line prompt, and navigate to the directory build/msw inside the wxWidgets directory. In this directory there 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:

-fno-keep-inline-dllexport

Some versions of the MinGW Windows Runtime Library will cause an error during compilation. See: Bug #269. If this is the case with the toolchain you are using then try this workaround:

-D_WIN32_IE=0x0603

To silence warnings that can significantly slow down the compilation process:

-Wno-unused-local-typedefs

and

-Wno-deprecated-declarations

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 next. This would be useful for your own 64-bit programs but 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.

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:

set PATH=X:\path\to\toolchain\bin;%PATH%

Where "X" is the drive letter, and "\path\to\toolchain\bin" is where your toolchain is located.

If your compilation fails for any reason then make sure to run the clean line before trying again.

Build Code::Blocks

Self-Hosting

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.

Open project

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.

Global Variables.png

Global wx.png

Prevent unnecessary warnings

Building Code::Blocks against the wxWidgets library will generate an excessive amount of warnings during the compilation. This 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 log. To silence these warnings, go to Compiler Settings:

Compiler Settings.png

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.

Unused Local Typedefs.png

Compile project

Make sure that "All" is selected as the target (blue arrow), and then click the Build icon (red arrow).

Compile All.png

If everything builds correctly your build messages should end with no errors.

Build Log.png

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.

Update Devel Output.png

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.

Update bat.png

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.

Update Output.png

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

Don't forget to run update.bat again after building the contributed plugins.

Build Workspace.png

Install Code::Blocks

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.

If you want to run Code::Blocks on a machine without your compiler toolchain being in the PATH then you will likely have to include, in the same directory as the codeblocks.exe is fine, support .dll files from your compiler toolchain. The easiest way to determine the required files is to not have your compiler toolchain in your PATH and repeatedly run Code::Blocks and copy over each .dll it says is missing until all have been found.