Difference between revisions of "Compile"

From FreeOrionWiki
Jump to: navigation, search
(Linux instructions now in a separate page.)
(All operating system-specific instructions are now listed on separate pages.)
Line 43: Line 43:
 
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.
 
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==
+
==Compilation==
  
Full compilation instructions and common Linux issues are listed in [[Compile_In_Linux]].
+
Compilation instructions and troubleshooting tips are available for the following operating systems:
 
+
* [[Compile_In_Linux|Linux]]
==Compiling in Windows==
+
* [[Compile_In_Windows|Windows]]
===Software requirements===
+
* [[Compile_In_MacOsX|MacOS X]]
 
+
====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 [http://msdn.microsoft.com/vstudio/express/visualc/download/ downloaded for free] from Microsoft.  The [http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/ 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 [http://sourceforge.net/project/showfiles.php?group_id=75752&package_id=236893 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:
+
 
+
* [http://www.python.org/download/ Python 2.5] - Needed for the SCons build system, and FreeOrion AI
+
 
+
* [http://www.scons.org/ 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===
+
 
+
# First, get the [http://sourceforge.net/project/showfiles.php?group_id=75752&package_id=236893 FreeOrion SDK] from SourceForge.
+
# Optionally, update FreeOrion to the latest revision in [[Compile#Subversion|SVN]] which should automatically also update GiGi.
+
 
+
====Compiling with MSVC 2005 IDE====
+
 
+
# Open msvc2005\FreeOrion\FreeOrion.sln
+
# 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.
+
# Use Build->Build Solution to build the three projects' release targets
+
 
+
====Compiling with MSVC 2008 IDE====
+
 
+
# Download or build binaries for Boost 1.35.  You can build from source using the Boost instructions, or get the precompiled installer from [http://www.boostpro.com/products/free Boost Consulting].
+
# Open msvc2008\FreeOrion\FreeOrion.sln
+
# 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.
+
# 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.
+
# Use Build->Build Solution to build the three projects' release targets
+
# 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====
+
 
+
# If not done already, get SCons and Python (see above)
+
# Build and install GiGi using the instructions in README.txt in the SDK
+
# 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 [http://developer.apple.com/tools/download/ 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 [[Compile#Common_Problem:_Segmentation_Fault|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 [http://www.freeorion.org/forum/viewtopic.php?t=406&highlight=vsnprintf]
+
 
+
'''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 [http://freeorion.org/forum/viewtopic.php?t=1826&start=18 this forum post] for the small patch to UI/TechTreeWnd.cpp.
+

Revision as of 19:55, 3 August 2008

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.

Compilation

Compilation instructions and troubleshooting tips are available for the following operating systems: