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

From Code::Blocks
m (→‎Checking the presence of libwxGTK library: Confirmed, upodate-alternatives works on Ubuntu Natty)
m (Small cleanup)
Line 31: Line 31:
 
==== Checking the presence of libwxGTK library ====
 
==== 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, well '''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]'''.
+
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]'''.
  
Alternatively you can do the same in command line (to give an idea, I don't say there is only 2 packages):
+
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
 
<pre>$ ls /usr/lib/libwx_gtk* //to verify the presence
Line 39: Line 39:
 
$ sudo apt-get install libwxgtk2.8-0</pre>
 
$ sudo apt-get install libwxgtk2.8-0</pre>
  
If you don't find any package you must install the library from source as described below, and you can redo this check afterwards to verify that the installation worked correctly.
+
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.
  
  
Line 64: Line 64:
 
====wxWidgets build====
 
====wxWidgets build====
  
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).
+
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.
 
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.
Line 83: Line 83:
 
  export PATH=/usr/bin:/opt/wx/2.8/bin:$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)
+
Add /opt/wx/2.8/lib to /etc/ld.so.conf (nano /etc/ld.so.conf)
 
then run:
 
then run:
 
  ldconfig
 
  ldconfig
Line 122: Line 122:
 
<pre> ./bootstrap</pre>
 
<pre> ./bootstrap</pre>
  
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:'''
+
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:'''
 
  aclocal:configure.in:61: warning: macro `AM_OPTIONS_WXCONFIG' not found in library
 
  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:
 
Then aclocal is having trouble finding the wxWidgets .m4 files.  You can do one of two things:
Line 138: Line 141:
  
 
'''''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).
 
'''''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).
 +
  
 
If you get something like
 
If you get something like
Line 146: Line 150:
 
  ACLOCAL_FLAGS="-I /usr/share/aclocal" ./bootstrap
 
  ACLOCAL_FLAGS="-I /usr/share/aclocal" ./bootstrap
  
(*Note// '''If you run ./bootstrap and get errors like''':
+
 
  : bad interpreter: File not found
+
'''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 SVN), all errors were gone.  
 
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 SVN), all errors were gone.  
 
//tiwag 051008*)<br>
 
//tiwag 051008*)<br>
Line 153: Line 158:
 
<br>
 
<br>
 
If configure aborts with some unspecific error message(".infig.status: error: cannot find input file: Makefile"), 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.
 
If configure aborts with some unspecific error message(".infig.status: error: cannot find input file: Makefile"), 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.
 +
  
 
====Installing Code::Blocks sources====
 
====Installing Code::Blocks sources====

Revision as of 22:24, 17 June 2011

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 recommanded because of some troubles). This creates an additional dependency on GTK+, consider the following:

A possible implementation which does not exist:

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

Current Code::Blocks implementation:

Code::Blocks -> xwWidget (> 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 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.

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

wxWidgets build

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 you're 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 as follows:

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

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


If you get something like

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

it can be solved by something like: (adapt path, use `wx-config --prefix` is necessary)

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


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 SVN), all errors were gone. //tiwag 051008*)
Or, instead of downloading from SVN, you might consider using the little command line tool dos2unix, which normally comes with most distributions. //lizzarddude060103
If configure aborts with some unspecific error message(".infig.status: error: cannot find input file: Makefile"), 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.


Installing Code::Blocks sources

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

 ./configure
 make
 make install

If you have multiple versions of wxWidgets installed or kept them inplace, 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 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.