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

From Code::Blocks
m (Changed order of the "Building Code::Blocks" parts)
m (→‎Downloading the latest source package: Corrected finalbeta to RC2)
Line 182: Line 182:
 
=====Downloading the latest source package=====
 
=====Downloading the latest source package=====
  
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.
+
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.0rc2 source code (tarball)" codeblocks-1.0rc2.tar.gz.
 
Save this file in <tt>~/devel</tt> and then untar it:
 
Save this file in <tt>~/devel</tt> and then untar it:
 
<pre>cd ~/devel
 
<pre>cd ~/devel
tar zxf codeblocks-1.0-finalbeta.tar.gz</pre>
+
tar zxf codeblocks-1.0rc2.tar.gz</pre>
This will create the directory <tt>~/devel/codeblocks-1.0-finalbeta</tt>.
+
This will create the directory <tt>~/devel/codeblocks-1.0rc2</tt>.
 
Change to the source code directory, by issuing the following command:
 
Change to the source code directory, by issuing the following command:
<pre>cd codeblocks-1.0-finalbeta/src</pre>
+
<pre>cd codeblocks-1.0rc2</pre>
  
 
=====Getting the latest sources from CVS=====
 
=====Getting the latest sources from CVS=====

Revision as of 22:29, 13 November 2005

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.


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. 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: GTK2 is required, not GTK1, for Code::Blocks to be operational.

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


wxGTK-2.4.2 installation

Getting wxGTK-2.4.2

Visit the 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 ~/devel.


Uncompressing the wxGTK sources

After the download finishes, switch to ~/devel:

cd ~/devel

Now, untar the wxGTK sources:

tar zxf wxGTK-2.4.2.tar.gz

or

tar jxf wxGTK-2.4.2.tar.bz2

depending on which file you downloaded.


Patching wxGTK

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:

//sgl/devel/grimoire/x11-toolkits/wxGTK/gtk-2.4-fix.patch#1 - add change 30747 (text)
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 );

(Patch copied from http://www.flamerobin.org/dokuwiki/doku.php?id=wiki:wxgtkpatch.)

Save the file as ~/devel/gtk-2.4-fix.patch and apply it by issuing:

cd ~/devel
patch -Np0 -i gtk-2.4-fix.patch

Now we can build wxGTK!


Building wxGTK-2.4.2

Issue the following commands to build wxGTK-2.4.2:

cd ~/devel/wxGTK-2.4.2
./configure --enable-gtk2
make

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

su -c "make install"

The above command will ask you for the root's password (you are working as a regular user, aren't you?) and then it will install the library and the needed development files in your system.

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:

cd contrib/src/stc
make
su -c "make install"

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:

cd ../xrc
make
su -c "make install"

NOTE: 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
cd build_gtk2_shared_monolithic_unicode
../configure --prefix=/opt/wx/2.6 \
       --enable-xrc \
       --enable-monolithic \
       --enable-unicode
make
make -C contrib/src/stc
su
make install
make -C contrib/src/stc install
exit

(Note: it's not necessary to make or install stc if you're compiling cvs HEAD or Code::Blocks newer than RC1)

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

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

(*Note// on Ubuntu Hoary it was necessary to check "Run command as login shell" in the gnome-terminal profile-settings, otherwise the PATH changes are not available in a gnome-terminal window. //tiwag 051008*)

add /opt/wx/2.6/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.6/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.6

wx-config --libs

which should have at least

-L/opt/wx/2.6/lib -lwx_gtk2-2.6

but can contain other flags as well.

which wx-config

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

Code::Blocks installation

Downloading Code::Blocks

You can get Code::Blocks source code in one of two ways:

  • Download the latest source package, or
  • Get the latest sources from the CVS repository.

Both methods, are described below.


Downloading the latest source package

Go to the Code::Blocks web site and download the latest source package. This would be the " Code::Blocks IDE version 1.0rc2 source code (tarball)" codeblocks-1.0rc2.tar.gz. Save this file in ~/devel and then untar it:

cd ~/devel
tar zxf codeblocks-1.0rc2.tar.gz

This will create the directory ~/devel/codeblocks-1.0rc2. Change to the source code directory, by issuing the following command:

cd codeblocks-1.0rc2
Getting the latest sources from CVS

For the following to work, you need to have the cvs command line client installed on your system. First you need to login to the CVS server:

cvs -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/codeblocks login

When asked for a password, press enter. Now, just checkout (i.e. download) the sources from the repository:

cd ~/devel
cvs -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/codeblocks co codeblocks

This will create the directory codeblocks. Change to the source code directory, by issuing the following command:

cd codeblocks/src


Building Code::Blocks RC2 and CVS

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

(*Note// If you run ./bootstrap and get errors like:

: bad interpreter: File not found

then there exists a problem with DOS line-endings. i had this error after i tried to build a codeblocks from sources which were checked out with cvs on a windows machine. After i checked out a fresh copy of codeblocks from cvs under Ubuntu linux (see above topic: Downloading the latest source package fom CVS), all errors were gone. //tiwag 051008*)

Once you've run the bootstrap script, installing is as simple as:

./configure
make
make install

To uninstall you can later run:

make uninstall

If you want to recompile everything, first run:

make clean

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

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

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

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


Building Code::Blocks RC1 and former

To build Code::Blocks all you have to do now is type:

make -f Makefile.unix

This will build everything: the application and the plugins. The final step is to update the working environment for your system:

make -f Makefile.unix update

The following notes about converting the line endings does not apply to the CVS Version! The "update" script included there works just fine.

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:

To install it in Gentoo, do:

# emerge -av dos2unix

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:

make -f Makefile.unix update

If everything's gone well, congratulations! You should be able to launch Code::Blocks by running the generated run.sh script in the output subdir:

output/run.sh

This script can be ran from anywhere in your system so, yes, you can make a shortcut to it on your desktop ;)

Enjoy!