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

From Code::Blocks
(Spelling)
 
(114 intermediate revisions by 29 users not shown)
Line 1: Line 1:
These are instructions on how to build Code::Blocks under Linux. I 've ran and verified this procedure to work under SuSE 9.2 and Fedora Core 3. These instructions should work for all Linux distros, as we 'll be installing from sources.
+
[[Category:Installing Code::Blocks]]
 
+
[[Category:Installing Code::Blocks from source]]
 +
These are instructions on how to build Code::Blocks under Linux. These instructions should work for all Linux distros, as we'll be installing from sources.
  
 
===Prerequisites===
 
===Prerequisites===
  
In order to sucesfully compile Code::Blocks, the wxWidgets (wxGTK-2.4.2) cross-platform UI library must be installed. In this document, it is not assumed that it is already installed in your system and instructions are given on how to download, build and install it.
+
In order to successfully compile Code::Blocks, the [http://en.wikipedia.org/wiki/WxWidgets wxWidgets] User Interface library <u>must be installed</u>. For most Linux users, this is maybe the only dependency not already installed. wxWidget can be used directly on top of the X server, in this case the variant of the wxWidget library is called wxX11. However this library [http://wiki.wxwidgets.org/WxWidgets_Compared_To_Other_Toolkits#Why_You_Shouldn.27t_Use_wxWidgets is sub-par compared to other toolkits and unstable]. Hence Code::Blocks uses wxGTK, the version of wxWidget based on GTK+. The exact requirement is libwxGTK-2.8.0 or later (2.8.3 is not recommended because of some troubles). This creates an additional dependency on GTK+, consider the following:
What is '''not''' covered here, is the wxWidgets prerequisites. The most important being GTK2, of course!
 
Let me stress it here, while it's early: <u>GTK2 is required</u>, not GTK1, for Code::Blocks to be operational.
 
  
All the instructions below, assume an existing directory named <tt>~/devel</tt>. If you 'll be using a different one, adjust the path to match.
+
A possible implementation which does not exist:  
As a first step create this directory:
 
  
<pre>mkdir ~/devel</pre>
+
''Code::Blocks  -> wxWidgets (libwxX11)  -> X''
  
 +
Current Code::Blocks implementation:
  
===wxGTK-2.4.2 installation===
+
''Code::Blocks  ->  '''wxWidgets (> libwxGTK2.8)'''  ->  '''GTK+ (> libgtk-x11-2.0)'''  ->  X''
====Getting wxGTK-2.4.2====
 
  
Visit the [http://www.wxwidgets.org wxWidgets] web site. Click on the "Download" button in the sidebar on the left side of the page. You want to download the file named wxGTK-2.4.2.tar.gz (or wxGTK-2.4.2.tar.bz2). Save the file in <tt>~/devel</tt>.
+
This document helps you to install libwxGTK if necessary but does not cover the installation of GTK+. GTK+ is probably installed on your Linux anyway, so don't worry ;)
  
  
====Uncompressing the wxGTK sources====
+
''Note:'' All the instructions below, assume an existing directory named <tt>~/devel</tt>. If you 'll be using a different one, adjust the path to match.
 +
As a first step create this directory:
  
After the download finishes, switch to <tt>~/devel</tt>:
+
<pre>mkdir ~/devel</pre>
  
<pre>cd ~/devel</pre>
+
=== Checking the presence of GTK+ library ===
  
Now, untar the wxGTK sources:
+
Have a look in /usr/lib ( /usr/lib/x86_64-linux-gnu for 64 bits) for something like "libgtk-x11-2.0.so" (Note the library must be 2.0 minimum). Alternatively, do a search with your package manager or go to your Linux distribution forum for help. If you don't want to loose time, you can even forget this check since there is a good probability that everything is already installed.
  
<pre>tar zxf wxGTK-2.4.2.tar.gz</pre>
+
===Library wxGTK installation===
  
or
+
==== Checking the presence of libwxGTK library ====
  
<pre>tar jxf wxGTK-2.4.2.tar.bz2</pre>
+
In your package manager, look for 'libwxgtk' keyword and verify that '''all''' libwxgtk2.8 stuffs are installed. If you find the libraries uninstalled, just '''install them and go directly to [https://wiki.codeblocks.org/index.php?title=Installing_Code::Blocks_from_source_on_Linux#Code::Blocks_installation Code::Blocks installation]'''.
  
depending on which file you downloaded.
+
Alternatively you can do the same in the command line (the following is an example, there may be more than two packages):
  
 +
<pre>$ ls /usr/lib/libwx_gtk* //to verify the presence
 +
$ sudo apt-get install libwxgtk2.8-dev
 +
$ sudo apt-get install libwxgtk2.8-0</pre>
  
=====Patching wxGTK=====
+
If you don't find any packages you must install the library from source as described below, and you can redo this check afterwards to verify that the installation worked correctly.
  
Most newer distros provide gtk2.4.x. Although wxGTK will compile using this gtk version, applications using this wxGTK will not compile succesfully. This happens because some internal function names were changed in later gtk versions and wxGTK-2.4.2, at the time of its release, did not account for these changes.
 
If your distro uses this gtk version, you will need to patch the wxGTK sources before the build process.
 
You can get the required patch from here (TODO: add link), or create a new file and put the following in it:
 
  
<pre>//sgl/devel/grimoire/x11-toolkits/wxGTK/gtk-2.4-fix.patch#1 - add change 30747 (text)
+
''Note for Debian and Ubuntu users:'' You can use
diff -Nur wxGTK-2.4.2/src/gtk/menu.cpp wxGTK-2.4.2-fix/src/gtk/menu.cpp
 
--- wxGTK-2.4.2/src/gtk/menu.cpp 2003-09-21 13:31:57.000000000 +0200
 
+++ wxGTK-2.4.2-fix/src/gtk/menu.cpp 2004-03-29 14:53:34.000000000 +0200
 
@@ -30,13 +30,13 @@
 
#ifdef __WXGTK20__
 
    #include <glib-object.h>
 
 
-    #define gtk_accel_group_attach(g, o) _gtk_accel_group_attach((g), (o))
 
-    #define gtk_accel_group_detach(g, o) _gtk_accel_group_detach((g), (o))
 
+    #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
 
+    #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
 
    #define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
 
 
-    #define ACCEL_OBJECT        GObject
 
+    #define ACCEL_OBJECT        GtkWindow
 
    #define ACCEL_OBJECTS(a)    (a)->acceleratables
 
-    #define ACCEL_OBJ_CAST(obj) G_OBJECT(obj)
 
+    #define ACCEL_OBJ_CAST(obj) GTK_WINDOW(obj)
 
#else // GTK+ 1.x
 
    #define ACCEL_OBJECT        GtkObject
 
    #define ACCEL_OBJECTS(a)    (a)->attach_objects
 
diff -Nur wxGTK-2.4.2/src/gtk/settings.cpp wxGTK-2.4.2-fix/src/gtk/settings.cpp
 
--- wxGTK-2.4.2/src/gtk/settings.cpp 2003-09-21 13:31:57.000000000 +0200
 
+++ wxGTK-2.4.2-fix/src/gtk/settings.cpp 2004-03-29 15:15:35.000000000 +0200
 
@@ -340,8 +340,8 @@
 
                } 
 
                else 
 
                { 
 
-                    const gchar *font_name =
 
-                        _gtk_rc_context_get_default_font_name(gtk_settings_get_default());
 
+                    gchar *font_name;
 
+                    g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL);
 
                    g_systemFont = new wxFont(wxString::FromAscii(font_name));
 
                } 
 
                gtk_widget_destroy( widget );
 
</pre>
 
<small>(''Patch copied from http://www.flamerobin.org/dokuwiki/doku.php?id=wiki:wxgtkpatch.'')</small>
 
  
Save the file as <tt>~/devel/gtk-2.4-fix.patch</tt> and apply it by issuing:
+
<pre>$ update-alternatives --config wx-config</pre>
  
<pre>cd ~/devel
+
to see which version of libwx is there or not and currently active.
patch -Np0 -i gtk-2.4-fix.patch</pre>
 
  
Now we can build wxGTK!
+
And, Debian and Ubuntu user can use this to add a value to the list of choices
  
 +
<pre>$ update-alternatives --install /usr/bin/wx-config wx-config /opt/wx/2.8/bin/wx-config 50</pre>
  
====Building wxGTK-2.4.2====
+
====Getting wxGTK sources====
  
Issue the following commands to build wxGTK-2.4.2:
+
Visit the [http://www.wxwidgets.org wxWidgets web site]. Click the "Download" button at the top of the page. Under wxWidgets 2.8.7 downloads, select wxGTK. Save the file in <tt>~/devel</tt>. After the download finishes, switch to <tt>~/devel</tt>:
  
<pre>cd ~/devel/wxGTK-2.4.2
+
<pre>cd ~/devel</pre>
./configure --enable-gtk2
 
make
 
</pre>
 
  
If something fails when you run the configure command, some wxGTK prerequisite is probably missing. Read through the output and figure out what's missing.
+
Now, untar the wxGTK sources:
If all's gone well, after 10 to 30 minutes (depending on your machine), the wxGTK library should be ready. Time to install it, system-wide:
 
  
<pre>su -c "make install"</pre>
+
<pre>tar zxf wxGTK-2.8.7.tar.gz</pre>
  
The above command will ask you for the root's password (you <u>are</u> working as a regular user, aren't you?) and then it will install the library and the needed development files in your system.
+
Switch to the wxGTK directory:
  
The next step is to build STC: the wxWidgets wrapper for Scintilla (the editor). This is located in the contrib subdir hierarchy. To do this, issue the following commands:
+
<pre>cd wxGTK-2.8.7</pre>
  
<pre>cd contrib/src/stc
+
====Building wxWidgets====
make
 
su -c "make install"</pre>
 
  
When you 're done, STC will have been installed too. All that's left, is the XRC library which is used to load XML resources. Type the following:
+
Here we will create a separate build directory instead of building from the src directory, so that we can easily rebuild with different options (unicode / ansi, monolithic / many libs, etc).
  
<pre>cd ../xrc
+
The documentation says the default is for gtk2 to use unicode and wx > 2.5 to build as a monolithic library.  This doesn't appear to be the case, so these flags are passed to configure:
make
 
su -c "make install"</pre>
 
 
 
<u>NOTE:</u> ''The Fedora Core 3 installation I tested this procedure, did not have /usr/local/lib in the library search path. I had to manually add /usr/local/lib in /etc/ld.so.conf as root and then issue ldconfig, as root again.''
 
 
 
That's it! If you reached here, congratulations! You 've built and installed wxGTK in your system.
 
You 're now ready to download and build Code::Blocks - i.e. the easy part :)
 
 
 
====wxWidgets 2.6.1 build====
 
 
 
In case you want to use wxGTK 2.6.1 instead.
 
Here we will create a seperate build directory instead of building from the src directory, so that we can easily rebuild with different options (unicode / ansi, monolithic / many libs, etc).
 
 
 
The documentation says the default is for gtk2 to use unicode and wx > 2.5 to build as a monolithic library.  This doesn't appear to be the case, so these flags are passed to configure.
 
  
 
  mkdir build_gtk2_shared_monolithic_unicode
 
  mkdir build_gtk2_shared_monolithic_unicode
 
  cd build_gtk2_shared_monolithic_unicode
 
  cd build_gtk2_shared_monolithic_unicode
  ../configure --prefix=/opt/wx/2.6 \
+
  ../configure --prefix=/opt/wx/2.8 \
 
         --enable-xrc \
 
         --enable-xrc \
 
         --enable-monolithic \
 
         --enable-monolithic \
 
         --enable-unicode
 
         --enable-unicode
 
  make
 
  make
make -C contrib/src/stc
 
 
  su
 
  su
 
  make install
 
  make install
make -C contrib/src/stc install
 
 
  exit
 
  exit
  
(Note: it's not necessary to make or install stc if you're compiling cvs HEAD)
+
Add /opt/wx/2.8/bin to the PATH (if your shell is bash then edit /etc/profile or ~/.bash_profile)
 +
(On ''Suse 10.1'' edit /etc/profile.local, it will only be available after a new login). An example PATH:
 +
export PATH=/usr/bin:/opt/wx/2.8/bin:$PATH
  
add /opt/wx/2.6/bin to the PATH (if you're shell is bash then edit /etc/profile or ~/.bash_profile).  an example PATH
+
Add /opt/wx/2.8/lib to /etc/ld.so.conf (nano /etc/ld.so.conf), then run:
export PATH=/usr/bin:/opt/wx/2.6/bin:$PATH
 
add /opt/wx/2.6/lib to /etc/ld.so.conf (nano /etc/ld.so.conf)
 
then run:
 
 
  ldconfig
 
  ldconfig
 
  source /etc/profile
 
  source /etc/profile
  
That's it.  Now the linker will look in /opt/wx/2.6/lib for wx libraries and you will have a monolithic shared library unicode build.
+
That's it.  Now the linker will look in /opt/wx/2.8/lib for wx libraries and you will have a monolithic shared library unicode build.
  
 
To check that things are working, type:
 
To check that things are working, type:
 
  wx-config --prefix
 
  wx-config --prefix
which should give you /opt/wx/2.6
+
which should give you /opt/wx/2.8
 
  wx-config --libs
 
  wx-config --libs
which should have at least
+
which should have at least:
  -L/opt/wx/2.6/lib -lwx_gtk2-2.6
+
  -L/opt/wx/2.8/lib -lwx_gtk2-2.8
 
but can contain other flags as well.
 
but can contain other flags as well.
 
  which wx-config
 
  which wx-config
should return /opt/wx/2.6/bin/wx-config
+
should return /opt/wx/2.8/bin/wx-config
  
 
===Code::Blocks installation===
 
===Code::Blocks installation===
  
====Downloading Code::Blocks====
+
====Getting Code::Blocks sources====
  
You can get Code::Blocks source code in one of two ways:
+
You can get Code::Blocks source code [https://www.codeblocks.org/downloads/25 from the website as a tarball] or from the [https://www.codeblocks.org/downloads/7 SVN repository] (this second method is described below).
* Download the latest source package, or
 
* Get the latest sources from the CVS repository.
 
Both methods, are described below.
 
  
 +
=====From SVN repository=====
 +
NOTICE: The SourceForge CVS is no longer used although it still exists.
  
=====Downloading the latest source package=====
+
Enter your development directory:
 +
<pre>cd ~/devel</pre>
  
Go to the Code::Blocks [https://www.codeblocks.org web site] and download the latest source package. This would be the " Code::Blocks IDE version 1.0-finalbeta source code (tarball)" codeblocks-1.0-finalbeta.tar.gz.
+
Then checkout the source using one of [https://www.codeblocks.org/downloads/7 these] methods. This will create the directory <tt>trunk</tt>. Change to the source code directory, by issuing the following command:
Save this file in <tt>~/devel</tt> and then untar it:
 
<pre>cd ~/devel
 
tar zxf codeblocks-1.0-finalbeta.tar.gz</pre>
 
This will create the directory <tt>~/devel/codeblocks-1.0-finalbeta</tt>.
 
Change to the source code directory, by issuing the following command:
 
<pre>cd codeblocks-1.0-finalbeta/src</pre>
 
  
=====Getting the latest sources from CVS=====
+
<pre>cd trunk</pre>
  
For the following to work, you need to have the <tt>cvs</tt> command line client installed on your system.
+
If you are a ''Gentoo'' user at this point, please see [[Compiling_Code::Blocks_in_Gentoo]].
First you need to login to the CVS server:
 
  
<pre>cvs -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/codeblocks login</pre>
+
Before beginning, it is often a good idea to check you have recent versions of autoconf and automake - repositories versions are not always recent enough. (if you do not have automake, then you will get "cannot find aclocal" error). If you're compiling the svn trunk versions of CodeBlocks (or future versions) then the unix build has switched to autotools. So first build wxWidgets as described above and then build CodeBlocks. In short, these commands build Code::Blocks from sources ''and'' installs it:
 +
<pre> ./bootstrap
 +
./configure
 +
make
 +
make install
 +
</pre>
  
When asked for a password, press enter.
+
The long story is as follows: First run:
Now, just checkout (i.e. download) the sources from the repository:
+
<pre> ./bootstrap</pre>
  
<pre>cd ~/devel
+
This sets up the configure script and its dependencies. It only needs to be run once (after downloading the source from svn).
cvs -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/codeblocks co codeblocks</pre>
 
  
This will create the directory <tt>codeblocks</tt>.
+
'''If you get errors like (...):'''
Change to the source code directory, by issuing the following command:
+
./bootstrap: libtoolize: not found
 +
...then install the "libtool" package using your package manager.
  
<pre>cd codeblocks/src</pre>
+
./bootstrap: 64: ./bootstrap: aclocal: not found
 +
...then the "autoconf" and "automake" package using your package manager.
  
 +
bad interpreter: File not found
 +
...then there exists a problem with DOS line-endings, for example if you cross compile to a Windows partition. Simply check-out a fresh copy of CodeBlocks from SVN.
 +
<br>
 +
Or, instead of downloading from SVN, you might consider using the little command line tool [http://dos2unix.sourceforge.net/ dos2unix], which normally comes with most distributions.
 +
<br>
  
====Building Code::Blocks====
+
  (".infig.status: error: cannot find input file: Makefile")
 +
...(configure aborts with some unspecific error messagelike that), then you might consider also running dos2unix bootstrap acinclude.m4 codeblocks.pc.in configure.in Makefile.am before running bootstrap. Once you've run the bootstrap script, jump to next step.
  
To build Code::Blocks all you have to do now is type:
+
aclocal:configure.in:61: warning: macro `AM_OPTIONS_WXCONFIG' not found in library
 +
...then aclocal is having trouble finding the wxWidgets .m4 files.  You can do one of two things:
 +
To just get bootstrap to find the path this time do:
 +
<pre>export ACLOCAL_FLAGS="-I `wx-config --prefix`/share/aclocal"</pre> <!--[[User:Jabber|Jabber]] 06:24, 2 August 2006 (EDT)-->
  
<pre>make -f Makefile.unix</pre>
+
To change the aclocal search path more permanently do:
 +
echo `wx-config --prefix`/share/aclocal >> /usr/share/aclocal/dirlist
 +
Then aclocal will also search somewhere like /opt/wx/2.8/share/aclocal
  
This will build everything: the application and the plugins. The final step is to update the working environment for your system:
+
'''''Note for Ubuntu users:''''' The above is not the correct way to fix the AM_* errors. Rather, you only need to install the package named "wx-common" (Universe repository).
  
<pre>make -f Makefile.unix update</pre>
+
The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
 +
...then this can be solved by something like:
 +
ACLOCAL_FLAGS="-I /usr/share/aclocal" ./bootstrap
 +
(...maybe adopting the path, so use `wx-config --prefix` is necessary.)
  
The following notes about converting the line endings does '''not''' apply to the CVS Version! The "update" script included there works just fine.
+
====Installing Code::Blocks sources====
 +
You can read the BUILD file included in the source, but everything is very straightforward. Do:
 +
<pre> ./configure
 +
make
 +
make install</pre>
  
'''Important note:''' Don't run that final make yet! The "update" script seems to be using Dos character encoding, which will result in its failure to run on Linux. To fix this, use dos2unix:
+
You may need to run make install with super user rights, in that case use:
 +
<pre> sudo make install</pre>
 +
...for the last step.
  
To install it in Gentoo, do:
+
If you have multiple versions of wxWidgets installed or kept them in place, you can use:
 +
./configure --with-wx-config=/path/to/wx-config
  
# emerge -av dos2unix
+
'''Note:''' 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. It is not checked for the existing of boost at the moment (except for debian build-system, there it is a build-dependency), so if you configure C::B to be build without Nassi Schneiderman, it should not lead to problems in case you don't have/want boost.
 
 
In Debian and Ubuntu, do (as root, or using sudo etc.):
 
 
 
# apt-get install sysutils
 
 
 
This will install dos2unix. Now we are ready to convert the script.
 
# dos2unix -n update update.unix
 
# chmod +x update.unix
 
# ./update.unix
 
The first line converts the script character encoding, the second makes it executable and the third runs it. This trick is from a forum post by ilkapo.
 
 
 
OK. Now that the update script is converted to unix format, you can run the final make:
 
 
 
<pre>make -f Makefile.unix update</pre>
 
 
 
If everything's gone well, congratulations! You should be able to launch Code::Blocks by running the generated <tt>run.sh</tt> script in the <tt>output</tt> subdir:
 
 
 
<pre>output/run.sh</pre>
 
 
 
This script can be ran from anywhere in your system so, yes, you can make a shortcut to it on your desktop ;)
 
 
 
Enjoy!
 
 
 
 
 
.............................................
 
 
 
 
 
If you're compiling the cvs HEAD verions of CodeBlocks (or future versions) then the unix build has switched to autotools.  So first build wxWidgets as described above and then build CodeBlocks as follows:
 
 
 
./bootstrap
 
 
 
This sets up the configure script and it's dependencies.  It only needs to be run once (after downloading the source from cvs).  If you get errors like:
 
aclocal:configure.in:61: warning: macro `AM_OPTIONS_WXCONFIG' not found in library
 
Then aclocal is having trouble finding the wxWidgets .m4 files.  You can do one of two things:
 
To just get bootstrap to find the path this time do:
 
export ACLOCAL_FLAGS="--acdir=`wx-config --prefix`/share/aclocal"
 
To change the aclocal search path more permanently do:
 
echo `wx-config --prefix`/share/aclocal >> /usr/share/aclocal/dirlist
 
Then aclocal will also search somewhere like /opt/wx/2.6/share/aclocal
 
 
 
Once you've run the bootstrap script, installing is as simple as:
 
./configure
 
make
 
make install
 
  
 
To uninstall you can later run:
 
To uninstall you can later run:
Line 269: Line 184:
  
 
If you want to recompile everything, first run:
 
If you want to recompile everything, first run:
  make clean
+
<pre> make clean
 +
make distclean
 +
make clean-bin
 +
  make clean-zipfiles</pre>
 
and then follow the above sequence for installing.
 
and then follow the above sequence for installing.
  
 
By default, CodeBlocks will install to /usr/local.  If you want it in its own tree (so you can have multiple versions of CodeBlocks, each in its own subdirectory of /opt) replace the above ./configure command with:
 
By default, CodeBlocks will install to /usr/local.  If you want it in its own tree (so you can have multiple versions of CodeBlocks, each in its own subdirectory of /opt) replace the above ./configure command with:
./configure --prefix=/opt/codeblocks-cvs
+
<pre> ./configure --prefix=/opt/codeblocks-svn</pre>
 
or similar.  Then you can later install a different build like:
 
or similar.  Then you can later install a different build like:
./configure --prefix=/opt/codeblocks2-cvs
+
<pre> ./configure --prefix=/opt/codeblocks2-svn</pre>
 +
followed by 'make && make install' as usual.
 +
 
 +
By default, CodeBlocks will not compile the contributed plugins from SVN.  If you want to compile / install them too, replace the above ./configure command with:
 +
<pre> ./configure --with-contrib-plugins=all</pre>
 
followed by 'make && make install' as usual.
 
followed by 'make && make install' as usual.
 +
 +
To see a list of other options available for configuring the build of CodeBlocks do:
 +
<pre> ./configure --help</pre>
 +
 +
To compile under ''Gentoo'', use:
 +
<pre> ./configure --with-wx-config=wx-config-2.8</pre>
 +
 +
====Resolving runtime issues====
 +
 +
When running Code::Blocks after the installation it might happen, that the system complains:
 +
codeblocks: error while loading shared libraries: libcodeblocks.so.0: cannot open shared object file: No such file or directory
 +
In that case make sure the library path where the Code::Blocks libraries where installed into is "known" to the system. For example: On Ubuntu using a default build process on a clean system will install the Code::Blocks executables to /use/local/bin and the libraries to /usr/local/lib. The latter is usually not known to a "clean" Ubuntu system. To add it to the search path for libraries do the following (as root / using sudo respectively):
 +
Add the following line to the file /etc/ld.so.conf:
 +
/usr/local/lib
 +
...and run:
 +
ldconfig
 +
That's it - Code::Blocks should now work just fine as all libraries are being found.
 +
 +
Note that for both you may need super user rights again - so use the sudo command as needed.

Latest revision as of 05:20, 8 July 2023

These are instructions on how to build Code::Blocks under Linux. These instructions should work for all Linux distros, as we'll be installing from sources.

Prerequisites

In order to successfully compile Code::Blocks, the wxWidgets User Interface library must be installed. For most Linux users, this is maybe the only dependency not already installed. wxWidget can be used directly on top of the X server, in this case the variant of the wxWidget library is called wxX11. However this library is sub-par compared to other toolkits and unstable. Hence Code::Blocks uses wxGTK, the version of wxWidget based on GTK+. The exact requirement is libwxGTK-2.8.0 or later (2.8.3 is not recommended because of some troubles). This creates an additional dependency on GTK+, consider the following:

A possible implementation which does not exist:

Code::Blocks -> wxWidgets (libwxX11) -> X

Current Code::Blocks implementation:

Code::Blocks -> wxWidgets (> libwxGTK2.8) -> GTK+ (> libgtk-x11-2.0) -> X

This document helps you to install libwxGTK if necessary but does not cover the installation of GTK+. GTK+ is probably installed on your Linux anyway, so don't worry ;)


Note: All the instructions below, assume an existing directory named ~/devel. If you 'll be using a different one, adjust the path to match. As a first step create this directory:

mkdir ~/devel

Checking the presence of GTK+ library

Have a look in /usr/lib ( /usr/lib/x86_64-linux-gnu for 64 bits) for something like "libgtk-x11-2.0.so" (Note the library must be 2.0 minimum). Alternatively, do a search with your package manager or go to your Linux distribution forum for help. If you don't want to loose time, you can even forget this check since there is a good probability that everything is already installed.

Library wxGTK installation

Checking the presence of libwxGTK library

In your package manager, look for 'libwxgtk' keyword and verify that all libwxgtk2.8 stuffs are installed. If you find the libraries uninstalled, just install them and go directly to Code::Blocks installation.

Alternatively you can do the same in the command line (the following is an example, there may be more than two packages):

$ ls /usr/lib/libwx_gtk* //to verify the presence
$ sudo apt-get install libwxgtk2.8-dev
$ sudo apt-get install libwxgtk2.8-0

If you don't find any packages you must install the library from source as described below, and you can redo this check afterwards to verify that the installation worked correctly.


Note for Debian and Ubuntu users: You can use

$ update-alternatives --config wx-config

to see which version of libwx is there or not and currently active.

And, Debian and Ubuntu user can use this to add a value to the list of choices

$ update-alternatives --install /usr/bin/wx-config wx-config /opt/wx/2.8/bin/wx-config 50

Getting wxGTK sources

Visit the wxWidgets web site. Click the "Download" button at the top of the page. Under wxWidgets 2.8.7 downloads, select wxGTK. Save the file in ~/devel. After the download finishes, switch to ~/devel:

cd ~/devel

Now, untar the wxGTK sources:

tar zxf wxGTK-2.8.7.tar.gz

Switch to the wxGTK directory:

cd wxGTK-2.8.7

Building wxWidgets

Here we will create a separate build directory instead of building from the src directory, so that we can easily rebuild with different options (unicode / ansi, monolithic / many libs, etc).

The documentation says the default is for gtk2 to use unicode and wx > 2.5 to build as a monolithic library. This doesn't appear to be the case, so these flags are passed to configure:

mkdir build_gtk2_shared_monolithic_unicode
cd build_gtk2_shared_monolithic_unicode
../configure --prefix=/opt/wx/2.8 \
       --enable-xrc \
       --enable-monolithic \
       --enable-unicode
make
su
make install
exit

Add /opt/wx/2.8/bin to the PATH (if your shell is bash then edit /etc/profile or ~/.bash_profile) (On Suse 10.1 edit /etc/profile.local, it will only be available after a new login). An example PATH:

export PATH=/usr/bin:/opt/wx/2.8/bin:$PATH

Add /opt/wx/2.8/lib to /etc/ld.so.conf (nano /etc/ld.so.conf), then run:

ldconfig
source /etc/profile

That's it. Now the linker will look in /opt/wx/2.8/lib for wx libraries and you will have a monolithic shared library unicode build.

To check that things are working, type:

wx-config --prefix

which should give you /opt/wx/2.8

wx-config --libs

which should have at least:

-L/opt/wx/2.8/lib -lwx_gtk2-2.8

but can contain other flags as well.

which wx-config

should return /opt/wx/2.8/bin/wx-config

Code::Blocks installation

Getting Code::Blocks sources

You can get Code::Blocks source code from the website as a tarball or from the SVN repository (this second method is described below).

From SVN repository

NOTICE: The SourceForge CVS is no longer used although it still exists.

Enter your development directory:

cd ~/devel

Then checkout the source using one of these methods. This will create the directory trunk. Change to the source code directory, by issuing the following command:

cd trunk

If you are a Gentoo user at this point, please see Compiling_Code::Blocks_in_Gentoo.

Before beginning, it is often a good idea to check you have recent versions of autoconf and automake - repositories versions are not always recent enough. (if you do not have automake, then you will get "cannot find aclocal" error). If you're compiling the svn trunk versions of CodeBlocks (or future versions) then the unix build has switched to autotools. So first build wxWidgets as described above and then build CodeBlocks. In short, these commands build Code::Blocks from sources and installs it:

 ./bootstrap
 ./configure
 make
 make install

The long story is as follows: First run:

 ./bootstrap

This sets up the configure script and its dependencies. It only needs to be run once (after downloading the source from svn).

If you get errors like (...):

./bootstrap: libtoolize: not found

...then install the "libtool" package using your package manager.

./bootstrap: 64: ./bootstrap: aclocal: not found

...then the "autoconf" and "automake" package using your package manager.

bad interpreter: File not found

...then there exists a problem with DOS line-endings, for example if you cross compile to a Windows partition. Simply check-out a fresh copy of CodeBlocks from SVN.
Or, instead of downloading from SVN, you might consider using the little command line tool dos2unix, which normally comes with most distributions.

 (".infig.status: error: cannot find input file: Makefile")

...(configure aborts with some unspecific error messagelike that), then you might consider also running dos2unix bootstrap acinclude.m4 codeblocks.pc.in configure.in Makefile.am before running bootstrap. Once you've run the bootstrap script, jump to next step.

aclocal:configure.in:61: warning: macro `AM_OPTIONS_WXCONFIG' not found in library

...then aclocal is having trouble finding the wxWidgets .m4 files. You can do one of two things: To just get bootstrap to find the path this time do:

export ACLOCAL_FLAGS="-I `wx-config --prefix`/share/aclocal"

To change the aclocal search path more permanently do:

echo `wx-config --prefix`/share/aclocal >> /usr/share/aclocal/dirlist

Then aclocal will also search somewhere like /opt/wx/2.8/share/aclocal

Note for Ubuntu users: The above is not the correct way to fix the AM_* errors. Rather, you only need to install the package named "wx-common" (Universe repository).

The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'

...then this can be solved by something like:

ACLOCAL_FLAGS="-I /usr/share/aclocal" ./bootstrap

(...maybe adopting the path, so use `wx-config --prefix` is necessary.)

Installing Code::Blocks sources

You can read the BUILD file included in the source, but everything is very straightforward. Do:

 ./configure
 make
 make install

You may need to run make install with super user rights, in that case use:

 sudo make install

...for the last step.

If you have multiple versions of wxWidgets installed or kept them in place, you can use:

./configure --with-wx-config=/path/to/wx-config

Note: 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. It is not checked for the existing of boost at the moment (except for debian build-system, there it is a build-dependency), so if you configure C::B to be build without Nassi Schneiderman, it should not lead to problems in case you don't have/want boost.

To uninstall you can later run:

make uninstall

If you want to recompile everything, first run:

 make clean
 make distclean
 make clean-bin
 make clean-zipfiles

and then follow the above sequence for installing.

By default, CodeBlocks will install to /usr/local. If you want it in its own tree (so you can have multiple versions of CodeBlocks, each in its own subdirectory of /opt) replace the above ./configure command with:

 ./configure --prefix=/opt/codeblocks-svn

or similar. Then you can later install a different build like:

 ./configure --prefix=/opt/codeblocks2-svn

followed by 'make && make install' as usual.

By default, CodeBlocks will not compile the contributed plugins from SVN. If you want to compile / install them too, replace the above ./configure command with:

 ./configure --with-contrib-plugins=all

followed by 'make && make install' as usual.

To see a list of other options available for configuring the build of CodeBlocks do:

 ./configure --help

To compile under Gentoo, use:

 ./configure --with-wx-config=wx-config-2.8

Resolving runtime issues

When running Code::Blocks after the installation it might happen, that the system complains:

codeblocks: error while loading shared libraries: libcodeblocks.so.0: cannot open shared object file: No such file or directory

In that case make sure the library path where the Code::Blocks libraries where installed into is "known" to the system. For example: On Ubuntu using a default build process on a clean system will install the Code::Blocks executables to /use/local/bin and the libraries to /usr/local/lib. The latter is usually not known to a "clean" Ubuntu system. To add it to the search path for libraries do the following (as root / using sudo respectively): Add the following line to the file /etc/ld.so.conf:

/usr/local/lib

...and run:

ldconfig

That's it - Code::Blocks should now work just fine as all libraries are being found.

Note that for both you may need super user rights again - so use the sudo command as needed.