Compile

From FreeOrionWiki
Revision as of 05:49, 1 August 2008 by Igrok (Talk | contribs) (Add PI/PS2INCH build error to Troubles and Questions in Compile.)

Jump to: navigation, search

Currently, FreeOrion will compile in Windows XP (SP2), Windows Vista and Linux. Mac OS X versions have been produced, but are not actively supported. The *BSD genus of operating systems might also work; follow the Linux instructions in this case, and drop us a note telling us what you did if you manage to build it.

Overview

First of all, you will need to obtain the source. This can be grabbed from our project page or from Subversion (SVN). The versions available on the project page are official releases or point releases, and may be somewhat or very out of date. To help with programming FreeOrion, you will need to grab the SVN copy. Then you need to set up the required software, compile the game, download the missing artwork, and run it.

Hardware requirements

The FreeOrion code makes heavy use of templates, and requires much memory to compile; at least 1 GB of RAM is reccomended, and at least 512 MB is strongly reccomended. If you have less than 256 MB of RAM plus at least the same amount of swap, you probably will run into trouble.

On Linux, if you have only 256 MB of RAM and want to speed up compilation significantly, you could shut down your X server and compile from console. (If this doesn't mean anything to you, simply ignore this advice.) Otherwise, your computer will spend 95% of the time swapping, but will finish, eventually.

You will also need a fast processor. Expect more than one hour for a first-time build on a 2 GHz processor (after building GG and any other necessary dependencies).

Software requirements

Note: On Windows, most dependencies are available precompiled in the FreeOrion SDK.

  • GiGi - Latest version from SourceForge SVN, will automatically be included in the FreeOrion/GG directory when checking out the FreeOrion Subversion archive
  • FreeType2 - a GiGi dependency
  • Boost - version 1.35 or later
  • log4cpp - version 0.3.4b
  • DevIL - a GiGi dependency (note: this has several sub-dependencies of its own)
  • SDL - a GiGi dependency
  • GraphViz - version 2.8
  • OpenAL and ALUT
  • libogg - version 1.1.3
  • libvorbis - version 1.1.2
  • Python - version 2.4 or later (version 2.5 if using the FreeOrion Windows SDK)
  • GLEW - (Windows only)
  • SCons - Optional on Windows, but required on Linux to build GiGi and FreeOrion

Getting the source

Subversion

The source code can be obtained from the sourceforge Subversion server, using this command from the Linux command prompt:

svn co https://freeorion.svn.sourceforge.net/svnroot/freeorion/trunk freeorion 

For Windows, a graphical shell-extention SVN client, such as TortoiseSVN is reccomended, with which the source can be obtained from https://freeorion.svn.sourceforge.net/svnroot/freeorion.

Package

You can download an older version of the software in a package from the project page. Remember that if you want to help develop, you will need to obtain a copy from Subversion.

Compiling in Linux

Each linux distribution will come with varying components already installed. Hopefully the notes below will help to identify what is required for your particular distribution.

Compiler

GCC 4.x is required. See this forum thread.

Bogus build errors

You may see errors during the build process like this:

Checking for fmod >= 3.75... no
Checking fmod version >= 3.75... yes 
Checking for C header file fmod.h... yes
Checking for FSOUND_GetVersion() in C library fmod-3.75... yes
Checking for graphviz >= 0.15.0... no
Checking for libdotneato >= 0.15.0... no
Checking for C header file graphviz/render.h... yes
Checking for begin_component() in C library dotgen... yes

These failed messages refer to scons not finding an installed package for these components. The subsequent successful checks show that despite there being no pkg-config ".pc" file, the required header and library files were successfully located.

Platform specifics

Ubuntu

To build gigi or FreeOrion you first need to install the following packages using Synaptic (you will need to have the Universe repository included):

  • python (should already be installed)
  • scons
  • libfreetype6 and libfreetype6-dev
  • bcp
  • libdevil1c2 and libdevil-dev
  • libsdl1.2debian (should already be installed), libsdl1.2-dev
  • graphviz and graphviz-dev

You can install all of these (including dependencies) from the command line using this:

sudo apt-get install python scons libfreetype6-dev bcp libdevil-dev libsdl1.2-dev libsdl-mixer1.2-dev graphviz-dev libalut-dev liblog4cpp5-dev
Ubuntu (FeistyFawn and EdgyEft)

The log4cpp libs are still missing, so lets install them:

sudo apt-get install liblog4cpp4 liblog4cpp4-dev
Ubuntu (DapperDrake and before)

Your Ubuntu log4cpp package is too old so you will need to download the required version from the Debian archive (liblog4cpp4 and liblog4cpp4-dev) then install them:

sudo dpkg --install liblog4cpp4_0.3.5-rc3-1_i386.deb
sudo dpkg --install liblog4cpp4-dev_0.3.5-rc3-1_i386.deb


GiGi

Before attempting to build FreeOrion you will first need to build and install the gigi library.

The GiGi source should be automatically downloaded from SVN along with the FreeOrion source code. If not, it can be manually downloaded:

svn co https://gigi.svn.sourceforge.net/svnroot/gigi/trunk gigi

Change into the gigi directory and build the library:

cd FreeOrion/GG
scons
sudo scons install

Since gigi will be periodically updated, you should refresh the files occasionally to keep it up to date:

cd FreeOrion/GG
svn update
scons
sudo scons install

FreeOrion

To build freeorion or rebuild after gigi or the freeorion source code has changed:

cd freeorion/FreeOrion
scons

If SCons can't find a dependency (eg. Boost) and you do have it, then you may need to configure the dependency directories before actually compiling. The command:

scons -h

lists the command-line options for SCons, including how to configure each dependency directories.

Clean After Dependency Changes

It has been reported that on Gentoo, it may be necessary to clean your old build before rebuilding GiGi or FreeOrion after updates that make changes to dependencies or versions of dependencies used, including as Boost. To do this:

scons --clean

Common Problem: Segmentation Fault

If after compiling everything, you run freeorion and get a segmentation fault:

$ ./freeorion
Segmentation fault

You might be mixing dependencies compiled with different versions of GCC. See this forum post, this other forum post, this third post and this section of Harm's Debian User Story.

User stories

Compiling in Windows

Software requirements

Compiler

To compile FreeOrion you can use the MSVC 2005 or MSVC 2008 IDEs or SCons. In any case, the MSVC compiler is required and will be used; compiling with SCons is done from the command-line, but uses the same compiler as the IDE. The 2003 compiler is no longer supported due to bugs which prevent FreeOrion from compiling.

Visual Studio 2005 Express Edition may be downloaded for free from Microsoft. The Platform SDK must be installed separately. Due to different registry keys being used, the Express Edition compiler may not be compatible with SCons, so if the newest version of SCons doesn't work, you'll have to use the project files to compile FreeOrion.

Visual Sutdio 2008 Express Edition is also available, but has not been tested with FreeOrion.

The commercial version of the Visual Studio 2005 compiler can be used with SCons or with the project files. The full version of Visual Studio 2008 has project files available, and should also work with SCons, but has not been tested.

Note that the MSVC 2005 Service Pack 1 is required for FreeOrion to compile properly.

Software Dependencies

The majority of FreeOrion dependencies can be found precompiled and packaged in the FreeOrion Windows SDK, from the SourceForge downloads page.

The SDK includes compiled libraries, headers and DLLs for: zlib, DevIL, SDL, GraphViz, Boost, log4cpp, FreeType, OpenAL, libvorbis, and libogg.

Other dependencies include:

  • Python 2.5 - Needed for the SCons build system, and FreeOrion AI
  • SCons - Needed to build GiGi and (optionally) FreeOrion itself
  • GiGi - This is included in the FreeOrion SDK. If building FreeOrion using SCons, GiGi but must be built from source and installed. All GiGi dependencies are in the FreeOrion SDK and should be automatically detected when GiGi is built. If using the MSVC project files, it is not necessary to build GiGi separately from FreeOrion, but all the GiGi dependencies are needed to build FreeOrion.

Compiling in Windows

  1. First, get the FreeOrion SDK from SourceForge.
  2. Optionally, update FreeOrion to the latest revision in SVN which should automatically also update GiGi.

Compiling with MSVC 2005 IDE

  1. Open msvc2005\FreeOrion\FreeOrion.sln
  2. Configure the Python include and lib directories to where these are located on your system. These are accessed in the GUI at (Project->Properties->C/C++->General) and (Project->Properties->Linker->General). This is essential only for the "freeorionca" project, but all three projects have the directories in their settings by default.
  3. Use Build->Build Solution to build the three projects' release targets

Compiling with MSVC 2008 IDE

  1. Download or build binaries for Boost 1.35. You can build from source using the Boost instructions, or get the precompiled installer from Boost Consulting.
  2. Open msvc2008\FreeOrion\FreeOrion.sln
  3. Configure the Python include and lib directories to where these are located on your system. These are accessed in the GUI at (Project->Properties->C/C++->General) and (Project->Properties->Linker->General). This is essential only for the "freeorionca" project, but all three projects have the directories in their settings by default.
  4. Configure the Boost lib directories to where these are locted on your system. As of this writing, the FreeOrion SDK does not contain libraries for Boost that work with MSVC 2008, so you need to point the IDE to where these are located.
  5. Use Build->Build Solution to build the three projects' release targets
  6. Copy boost_python-vc90-mt-1_35.dll from the boost lib directory into the directory where the freeorion executables are located. (This file is also not present in the SDK in a version compatible with MSVC 2008)

Compiling with SCons

  1. If not done already, get SCons and Python (see above)
  2. Build and install GiGi using the instructions in README.txt in the SDK
  3. Follow the instructions in the FreeOrion SDK, as with GiGi.

Note that using SCons reduces compile time compared to compiling with the MSVC IDE by only building common object files once, instead of once for each executable.

Compiling in MacOsX

WIP As of Nov. 20, 2007 you can download an SDK which contains all the necessary libraries as universal binaries and an Xcode project. Building with Scons is not supported so far.

Software requirements

  • Subversion
  • Xcode >= 2.4. To compile FreeOrion you need the Developer Tools which can be downloaded from Apple. If you already have Xcode installed but it is older than 2.4 you should update.

SDK

The libraries (with include files) in the SDK are:

  • Dynamic Libraries
    • libpng
    • DevIL (only linked against libpng)
    • libjpeg
    • graphviz
    • libltdl (i'm not entirely sure whether this library is already installed by default on mac os x or wether it comes with the developer tools)
    • libz
  • Frameworks
    • SDL
    • Ogg
    • Vorbis
  • Static Libraries
    • log4ccp
    • freetype2
    • Boost 1.35 (only filesystem, python, serialization, signals, thread)

The Python as the OpenAL framework should already come with MacOsX.

The FreeOrion & GiGi source code has to be obtained separately though:

Open the console and change to the directory where you want the root of the source tree of FreeOrion to reside. Then obtain the source:

 svn co https://freeorion.svn.sourceforge.net/svnroot/freeorion/trunk freeorion

After subversion has done its thing you have to apply two patches to the code.

Change to the FreeOrion source directory

cd freeorion/FreeOrion

. Then obtain the patches and apply them:

curl http://n.ethz.ch/student/schwadri/download/fo_macosx.patch | patch -p0
cd GG
curl http://n.ethz.ch/student/schwadri/download/gg_macosx.patch | patch -p0
cd ..

Now download the SDK and unpack it

curl http://n.ethz.ch/student/schwadri/download/osx.tar.bz2 | tar xj

Done. In the newly created "osx" directory you will find the Xcode project to build the code.

Building the Libraries by yourself

It's best to just stick with the SDK and just build the libraries yourself if you encounter problems with the ones included in the SDK.

Most of the problems with building the libraries arise because not all of them are that easy to build as universal binaries. In the worst case you'll have to build the binaries twice and then combine the result using

lipo

The following versions are known to work:

  • SDL 1.2.11
  • log4cpp 0.3.5 rc3
  • graphviz 2.8: You can either download a prebuilt binary version from http://www.ryandesign.com/graphviz/ or build it yourself
  • freetype 2.2.1
  • libpng 1.2.12
  • log4cpp 0.3.5 RC3
  • Boost 1.35.0
  • DevIL 1.6.8 RC1 (RC2 has problems with aclocal and automake)

Boost 1.34.1

Note: The Boost version used by FreeOrion has been updated 1.35.0. The information in this section may be out of date.

In order to build universal versions of the libraries you have to apply a patch to the darwin toolset. The patch can be found in the SDK in the directory dep/util. Copy it to the root directory of the boost source tree and call

patch -p0 < boost_darwin.patch

Then call

./configure

This builds the bjam tool and creates the user-config.jam file.

./tools/jam/src/bin.macosxx86/bjam toolset=darwin arch=fat sdkroot=10.4

and after some (not too short) time

sudo ./tools/jam/src/bin.macosxx86/bjam toolset=darwin arch=fat sdkroot=10.4 install

SDL, Ogg, Vorbis

Building those is pretty straightforward. They all come with an Xcode project supplied. Just make sure that the install_path of the Framework is configured correctly if you plan on having it in the application bundle.

libpng

./configure
make CC="gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk

log4cpp 0.3.5 rc3

open include/log4cpp/manipulator.hh and remove ';' on line 29

./configure CXX="g++ -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
make clean
make
cd src/
mkdir .lipos
mv .libs/liblog4cpp.4.0.5.dylib .lipos/
mv .libs/liblog4cpp.a .lipos/
cd ..
./configure CXX="g++ -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
make clean
make
cd src
mv .lipos/liblog4cpp.4.0.5.dylib .libs/liblog4cpp.4.0.5.dylib_i386
mv .lipos/liblog4cpp.a .libs/liblog4cpp.a_i386
rmdir .lipos
cd .libs
lipo -arch i386 liblog4cpp.4.0.5.dylib_i386 -arch ppc liblog4cpp.4.0.5.dylib -create -output liblog4cpp.4.0.5.dylib
lipo -arch i386 liblog4cpp.a_i386 -arch ppc liblog4cpp.a -create -output liblog4cpp.a
rm liblog4cpp.a_i386
rm liblog4cpp.4.0.5.dylib_i386
sudo make install

graphviz-2.8

build before libjpeg and freetype2 or with disabled jpeg and font support

sudo rm -rf /usr/local/lib/graphviz
sudo rm -rf /usr/local/include/graphviz
for arch in i386 ppc
do
	./configure CC="gcc -arch ${arch} -isysroot /Developer/SDKs/MacOSX10.4u.sdk" CPP="gcc -E -arch ${arch} -isysroot /Developer/SDKs/MacOSX10.4u.sdk" --without-freetype --without-x
	make clean
	make
	cd lib
	for dirname in $(ls -A)
	do
		if [ -d $dirname ] ; then
			cd $dirname
			if [ -d .libs ] ; then			
				if ( ! [[ -d .libs_${arch} ]] ) ; then
					mkdir .libs_${arch}
				fi
				cd .libs
				for libname in $(ls *.dylib *.a)
				do
					if ( ! [ -h $libname ] ) ; then
						mv $libname ../.libs_${arch}
					fi
				done
				cd .. 
			fi
			cd ..
		fi
	done
	cd ..
done

#lipo time
cd lib
for dirname in $(ls -A)
do
	if [ -d $dirname ] ; then
		cd $dirname
		if (  -d .libs_i386  &&  -d .libs_ppc  &&  -d .libs  ) ; then
			for libname in $(cd .libs_i386 ; ls *.dylib *.a) ; do
				lipo -arch i386 .libs_i386/${libname} -arch ppc .libs_ppc/${libname} -create -output .libs/${libname}
			done
		fi
		cd ..
	fi
done
cd ..

sudo make install

libjpeg

Mac OS X 10.3 and later ship with GNU libtool, albeit under a slightly different name, glibtool. We need only link to it to build the dynamic version of libjpeg that GD4O needs to work. Change into the build directory:

cd ../jpeg-6b/
ln -s `which glibtool` ./libtool

However, on Mac OS X 10.4 (Tiger), the libtool needs to be specified the build environment. Enter:

setenv MACOSX_DEPLOYMENT_TARGET 10.4

in tcsh, or:

export MACOSX_DEPLOYMENT_TARGET=10.4

in bash. Now configure with shared library support, then build and install:

./configure --enable-shared && make && sudo make install

configure will complain about ltconfig: cannot guess host type; you must specify one. An alternative to symlinking libtool is to copy its skeletal configuration defaults, as suggested by a correspondent (meaning, I haven't verified this):

cd ../jpeg-6b
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure CC="gcc -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk" --enable-shared
make
sudo make install
sudo ranlib /usr/local/lib/libjpeg.a


freetype-2.1.10

export CFLAGS=-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk 
export LDLAGS=-arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk 
 cd ../freetype-2.1.10

By default, freetype2's support for hinting TrueType fonts is disabled. US citizens using this library for commercial purposes might be liable for patent infringement by turning it back on; those of us to which US patents don't apply, or whomever may not care (I am not advocating infringement), edit the file include/freetype/config/ftoption.h and uncomment line 439 to read:

#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER

Proceed as before:

 ./configure && make && sudo make install

libDevIL

make sure that there is no previous version installed under /usr/local/lib that could be found by configure. otherwise this can break the build process

sudo rm -rf /usr/local/include/IL
sudo rm /usr/local/lib/libIL*
aclocal
automake
./configure CC="gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk" CPP="/usr/bin/cpp" CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
make clean
make
cd src-IL/src/
mkdir .lipos
mv .libs/libIL.1.0.0.dylib .lipos/
cd ../..
cd src-ILU/src/
mkdir .lipos
mv .libs/libILU.1.0.0.dylib .lipos/
cd ../..
cd src-ILUT/src
mkdir .lipos
mv .libs/libILUT.1.0.0.dylib .lipos/
cd ../..
./configure CC="gcc -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk" CPP="/usr/bin/cpp" CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
make clean
make
cd src-IL/src/
mv .lipos/libIL.1.0.0.dylib .libs/libIL.1.0.0.dylib_i386
rmdir .lipos
cd .libs
lipo -arch i386 libIL.1.0.0.dylib_i386 -arch ppc libIL.1.0.0.dylib -create -output libIL.1.0.0.dylib
rm libIL.1.0.0.dylib_i386
sudo /usr/bin/install -c libIL.1.0.0.dylib /usr/local/lib/libIL.1.0.0.dylib
cd ../../..
cd src-ILU/src/
mv .lipos/libILU.1.0.0.dylib .libs/libILU.1.0.0.dylib_i386
rmdir .lipos
cd .libs
lipo -arch i386 libILU.1.0.0.dylib_i386 -arch ppc libILU.1.0.0.dylib -create -output libILU.1.0.0.dylib
rm libILU.1.0.0.dylib_i386
sudo /usr/bin/install -c libILU.1.0.0.dylib /usr/local/lib/libILU.1.0.0.dylib
cd ../../..
cd src-ILUT/src/
mv .lipos/libILUT.1.0.0.dylib .libs/libILUT.1.0.0.dylib_i386
rmdir .lipos
cd .libs
lipo -arch i386 libILUT.1.0.0.dylib_i386 -arch ppc libILUT.1.0.0.dylib -create -output libILUT.1.0.0.dylib
rm libILUT.1.0.0.dylib_i386
sudo /usr/bin/install -c libILUT.1.0.0.dylib /usr/local/lib/libILUT.1.0.0.dylib
cd ../../..
(sudo cd /usr/local/lib && sudo rm -f libIL.1.dylib && sudo ln -s libIL.1.0.0.dylib libIL.1.dylib)
(sudo cd /usr/local/lib && sudo rm -f libIL.dylib && sudo ln -s libIL.1.0.0.dylib libIL.dylib)
(sudo cd /usr/local/lib && sudo rm -f libILU.1.dylib && sudo ln -s libILU.1.0.0.dylib libILU.1.dylib)
(sudo cd /usr/local/lib && sudo rm -f libILU.dylib && sudo ln -s libILU.1.0.0.dylib libILU.dylib)
(sudo cd /usr/local/lib && sudo rm -f libILUT.1.dylib && sudo ln -s libILUT.1.0.0.dylib libILUT.1.dylib)
(sudo cd /usr/local/lib && sudo rm -f libILUT.dylib && sudo ln -s libILUT.1.0.0.dylib libILUT.dylib)
sudo mkdir /usr/local/include/IL
sudo /usr/bin/install -c -m 644 include/IL/il.h /usr/local/include/IL/il.h
sudo /usr/bin/install -c -m 644 include/IL/ilu.h /usr/local/include/IL/ilu.h
sudo /usr/bin/install -c -m 644 include/IL/ilut.h /usr/local/include/IL/ilut.h
sudo /usr/bin/install -c -m 644 include/IL/il_wrap.h /usr/local/include/IL/il_wrap.h
sudo /usr/bin/install -c -m 644 include/IL/config.h /usr/local/include/IL/config.h
sudo /usr/bin/install -c -m 644 include/IL/devil_internal_exports.h /usr/local/include/IL/devil_internal_exports.h
sudo /usr/bin/install -c -m 644 include/IL/ilu_region.h /usr/local/include/IL/ilu_region.h

Troubles and Questions

Q. I get a segmentation fault as soon as I run freeorion

$ ./freeorion
Segmentation fault

A. See above.

Q. I get an undefined reference to `_vsnprintf'

A. This is a bug in the latest version of Devil. GiGi's configure script should've taken care of it. If it didn't, you can fix the error yourself: Check the il_tiff.c file and add this line at the top:

#define _vsnprintf vsnprintf 

and then recompile [1]

Q. I get an error saying: "Video mode set failed: Couldn't find matching GLX visual"

A. Your video mode is probably set to 16 bit instead of 32, which is what FreeOrion defaults to. You need to either change your X color depth, or edit the FreeOrion config file in default/config.xml. Change color-depth from 32 to 16. Since this file isn't included in a fresh download anymore, rather start with a --color-depth 16 command line argument.

Q. I get a compile error: "UI/TechTreeWnd.cpp:99: error: 'PI' was not declared in this scope"

A. Recent versions of graphviz do not define PI or PS2INCH. See this forum post for the small patch to UI/TechTreeWnd.cpp.