MainDocs:GNU C++ on Linux

From ClanLib Game SDK

ClanLib does not provide Linux binaries, and if your distribution does, they may well be out of date (e.g. Ubuntu 11.10's libclanlib-dev is ClanLib 1.0). The recommended way to install ClanLib on Linux is hence to compile it from source, as follows.

Contents

Installing prerequisites

ClanLib requires a C++ compiler and a number of other libraries; how to install these depends on which Linux distribution you are using. The following command downloads and installs everything required to allow use of all parts of ClanLib. If you have a slow internet connection and only intend to use some ClanLib modules, you may want to look at the #Module-by-module dependency list instead.

Debian / Ubuntu

sudo apt-get install make automake autoconf autotools-dev m4 libtool libc6-dev linux-libc-dev g++ \
zlib1g zlib1g-dev libpng12-0 libpng12-dev libjpeg62-dev libfreetype6 libfreetype6-dev \
x11proto-xf86vidmode-dev libxxf86vm-dev libfontconfig1-dev libxi-dev libgl1-mesa-dev \
libice-dev libsm-dev libx11-dev libxau-dev libxdmcp-dev libxext-dev libxt-dev mesa-common-dev \
x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-xext-dev xtrans-dev libasound2-dev \
libmikmod2 libmikmod2-dev libvorbis0a libvorbis-dev libogg-dev libpcre3 libpcre3-dev libsqlite3-dev libxrender-dev doxygen

Some 3D examples require assimp. See the AssimpLinux page.

Fedora

sudo yum install make automake autoconf autotools-dev m4 libtool libc6-dev linux-libc-dev g++ \
zlib1g zlib1g-dev libpng12-0 libpng12-dev libjpeg62-dev libfreetype6 libfreetype6-dev \
x11proto-xf86vidmode-dev libxxf86vm-dev libfontconfig1-dev libxi-dev libgl1-mesa-dev \
libice-dev libsm-dev libx11-dev libxau-dev libxdmcp-dev libxext-dev libxt-dev mesa-common-dev \
x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-xext-dev xtrans-dev libasound2-dev \
libmikmod2 libmikmod2-dev libvorbis0a libvorbis-dev libogg-dev libpcre3 libpcre3-dev libsqlite3-dev libxrender-dev doxygen pcre-devel libmikmod-devel

Some 3D examples require assimp. See the AssimpLinux page.

Downloading and configuring ClanLib

Download the latest ClanLib release source archive.

Open a terminal prompt and change to the directory you downloaded ClanLib to.

Extract:

tar -xvzf ClanLib-2.3.5.tgz

(Amend the version number as necessary)

Configure (this gives the standard one, see below for other options):

./configure --prefix=/usr

Development version

Alternatively, if you want the very latest features and are willing to live with a higher risk of bugs, download the current development source code from the subversion repository. (Not recommended at the moment on linux)

This version requires autogen before configure:

./autogen.sh
./configure --prefix=/usr

(If you get: "configure.ac:178: error: possibly undefined macro: AC_MSG_CHECKING", you will need to install the pkg-config package")

Alternative configurations

To get a list of available options, run "./configure --help"

Developers may prefer to add --enable-debug to create debug libraries.

You can force enabling of implementations, or disable some - eg.:

 ./configure --disable-clanMikMod --enable-clanGL

By default both shared (.so) and static (.a) libraries are built. Unless you want to make a static release, you will probably only want the shared libraries, so can disable the static ones with:

 ./configure --disable-static

Doing so will reduce the compile size by a half.

Compiling and installing

Compile (this will take some time):

make

Install:

sudo make install

ClanLib should now be ready for use.

Documentation and examples

ClanLib includes API reference documentation within its source files, which can be extracted to HTML using:

./configure --prefix=/usr --enable-docs
make html

It will then be found at file:///your ClanLib directory/Documentation/Reference/doxyoutput/html/modules.html

ClanLib also includes a number of examples, which are compiled and run as follows (replace Display/Basic2D with the example category and name):

cd Examples/Display/Basic2D
make
./basic2d

On fedora linux, if you get "Package clanApp-2.3 was not found in the pkg-config search path", this command helps fix the problem

export PKG_CONFIG_PATH=/usr/lib/pkgconfig

Using ClanLib

These examples compile and link a source file named mygame.cpp with the ClanLib 2.3.x modules required for graphics (2D or 3D, using OpenGL 2+) and input. If you use other parts of ClanLib such as networking (clanNetwork), sound (clanSound, and clanVorbis or clanMikmod if you use those formats) or GUI (clanGUI), a different graphics target (clanGL1 or clanSWRender) or a different ClanLib version, amend them accordingly.

Command line

g++ -o mygame mygame.cpp `pkg-config --cflags --libs clanCore-2.3 clanDisplay-2.3 clanGL-2.3 clanGL1-2.3 clanApp-2.3` -lpthread

Makefile

PACKAGES = clanCore-2.3 clanDisplay-2.3 clanApp-2.3 clanGL-2.3
LIBS = `pkg-config --cflags --libs $(PACKAGES)`
OBJS = mygame.o

all: $(OBJS)
	g++ -o mygame -pthread $(OBJS) $(LIBS)

clean:
	-rm -rf *.o
	-rm mygame

Module-by-module dependency list

automake
autoconf
autotools-dev
m4
libtool
libc6-dev
linux-libc-dev
g++ (g++-4.1 or later and libstdc++6-4.1-dev or later)
zlib1g
zlib1g-dev
libpng12-0
libpng12-dev
libjpeg62-dev
libfreetype6  (unless compiled manually)
libfreetype6-dev (unless compiled manually)
x11proto-xf86vidmode-dev (to enable XF86 VidMode)
libxxf86vm-dev (to enable XF86 VidMode)
libfontconfig1-dev
libxi-dev
libgl1-mesa-dev
libice-dev
libsm-dev
libx11-dev
libxau-dev
libxdmcp-dev
libxext-dev
libxt-dev
mesa-common-dev
x11proto-core-dev
x11proto-input-dev
x11proto-kb-dev
x11proto-xext-dev
xtrans-dev
libasound2-dev  (for alsa)
libmikmod2
libmikmod2-dev
libvorbis0a
libvorbis-dev
libogg-dev
libpcre3
libpcre3-dev
doxygen

ClanSDL is no longer part of ClanLib (replaced by clanSWRender), though it remains available as a separate clanSDL package.