Difference between revisions of "Compile In Linux"

From FreeOrionWiki
Jump to: navigation, search
(Bogus build errors: Not applicable anymore)
m (Compiling FreeOrion)
(34 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
For the most up-to-date instructions we recommend you begin by consulting [https://github.com/freeorion/freeorion/blob/master/BUILD.md the build instructions in our repository].  The information below may possibly add some helpful details, but is also at greater risk of being out of date.
 +
 
Each linux distribution will come with varying components already installed, although some libraries may be older than the version required by FreeOrion.  Hopefully the notes below will help to identify what is required for your particular distribution.
 
Each linux distribution will come with varying components already installed, although some libraries may be older than the version required by FreeOrion.  Hopefully the notes below will help to identify what is required for your particular distribution.
  
Line 4: Line 6:
 
==Compiler==
 
==Compiler==
  
Required compiler is gcc and g++ in version 4.3.3 or above.
+
Required compiler is gcc and g++ version 5.0 or above. cmake must be version 3.1 or later.
  
==Kernel==
+
For anyone who is going to be doing dev work or otherwise experimenting with multiple different builds,
If you compile using kernel 2.6.22 or above, your binary will likely not run on any other system having a lower numbered kernel version. This is due to a feature called "eventfd" which boost uses if a kernel 2.6.22 or above is found.
+
[https://ccache.samba.org/ ccache] (probably available via your package manager) is very highly recommended,  
 
+
for speeding up recompilation.  When having previously compiled FreeOrion in a different build directory,
To avoid this incompatibility, you can specify CPPDEFINES="BOOST_ASIO_DISABLE_EVENTFD" as a parameter to scons to disable usage of eventfd.
+
and now compiling FO for the first time in a new build directory to keep the executables distinct, without
 
+
ccache the compiler will redo the entire compilation process, but with ccache the process can be sped up roughly five-fold or more.
This issue should not be a problem at all if you don't share your binaries.
+
  
 
==Platform specifics==
 
==Platform specifics==
 
===OpenSuSE 12.2===
 
See [http://www.freeorion.org/forum/viewtopic.php?p=56109#p56109 this forum post].
 
  
 
===Ubuntu===
 
===Ubuntu===
This is a revision pass as of April 2014; hopefully it brings things current but may need some further revisionThese revised instructions are hopefully generic to most Ubuntu releases as of April 2014, and should work for Lucid through Trusty subject to the extra notes below. You can check which version of a given package is provided by your Ubuntu release [http://packages.ubuntu.com/search?keywords=libboost-dev at this page]
+
This is a revision pass as of June 2015.  You can check which version of a given package is provided by your Ubuntu release [http://packages.ubuntu.com/search?keywords=libboost-dev at this page]
 
To build gigi or FreeOrion you first need to install the following packages (using Synaptic or muon or apt-get) (you will need to have the [https://help.ubuntu.com/community/Repositories/Ubuntu#head-5bbef89639d9a7d93fe38f6356dc17847d373096 '''Universe''' repository included]):
 
To build gigi or FreeOrion you first need to install the following packages (using Synaptic or muon or apt-get) (you will need to have the [https://help.ubuntu.com/community/Repositories/Ubuntu#head-5bbef89639d9a7d93fe38f6356dc17847d373096 '''Universe''' repository included]):
 
*build-essential
 
*build-essential
 
*pkg-config
 
*pkg-config
*python-dev (python 2.5+, preferably 2.7, but not python3)
+
*python2.7-dev (python 2.7.x, but not python3)
 
*cmake
 
*cmake
*libltdl-dev
+
*git
*subversion
+
 
*libfreetype6-dev
 
*libfreetype6-dev
*libsdl1.2-dev
+
*libglew-dev
*libalut-dev
+
*libsdl2-dev
 
*libvorbis-dev
 
*libvorbis-dev
*libois-dev
 
 
*libopenal-dev
 
*libopenal-dev
*libtiff4-dev
+
*libboost-all-dev
  
 
You can install all of these (including dependencies) from the command line using this:
 
You can install all of these (including dependencies) from the command line using this:
  sudo apt-get install build-essential subversion pkg-config libltdl-dev cmake
+
  sudo apt-get install build-essential git pkg-config cmake libboost-all-dev libglew-dev
  sudo apt-get install python-dev libfreetype6-dev libsdl1.2-dev libalut-dev libvorbis-dev libois-dev libtiff4-dev libopenal-dev
+
  sudo apt-get install python2.7-dev libfreetype6-dev libsdl2-dev libvorbis-dev libopenal-dev
  
Also required are Boost, Ogre3D and Bullet.
+
Boost (libboost-all-dev) will need to be at least 1.56+ ([http://packages.ubuntu.com/search?keywords=libboost-all-dev check here]).
Boost (libboost-dev) will need to be at least 1.47+, and will preferably be 1.51+ ([http://packages.ubuntu.com/search?keywords=libboost-dev check here]).  If your Ubuntu release provides a sufficient boost release then you can install it via
+
sudo apt-get install libboost-all-dev
+
 
+
Ogre3D (libogre-dev) needs to have been compiled with the same version of boost as you will be using to compile FreeOrion (can be checked via muon or synaptic), so if you have any uncertainty it may be best to compile Ogre3D yourself per instructions below. To install your releases standard Ogre version you can use the following on the command line:
+
sudo apt-get install libogre-dev
+
 
+
Bullet 2.73(or later), which is required to compile, is not in the official Ubuntu repository; see below for instructions.
+
 
+
====Ubuntu Lucid====
+
See [[Compile In Ubuntu Lucid Lynx]].
+
You have to compile required version of Boost(in Lucid there is no version 1.47 or later) or get it from some repository.
+
  
 
===Debian===
 
===Debian===
Same as Ubuntu, but Bullet 2.73(or later), which is required to compile, is not in Debian repository. Also remove sudo from all commands and run these commands under root(to login type su). Ogre3D in required version is available only from Squeeze up.
+
For building the latest stable release in debian follow the directions here: [[Download#Building_from_source_the_Debian_way]]
 +
For building the most recent test versions you might want to follow the portion of those instructions for dependencies and then follow the regular Linux build instructions to get and build the most recent test version.
 +
If you have a debian based distribution for which these instructions don't work for you, then use the Ubuntu instructions as a guideline. You may also need to remove sudo from all commands and run these commands under root(to login type su).
  
====Lenny====
+
==FreeOrion==
Lenny provides version 1.35 of boost. You have to compile version 1.47 (or later) yourself.
+
===Compiling FreeOrion===
 
+
Compile FreeOrionIt is advisable (for some environments necessary) to make a separate build directory; apparently for many people (this make be related to cmake version) it is necessary that the build folder be entirely outside the source tree. ''So if starting in the directory within which the'' 'freeorion' ''source tree resides'', then the commands would be
====Squeeze (testing) & Sid (unstable)====
+
mkdir freeorion_build
You can install Boost and Ogre3D with command(under user root):
+
cd freeorion_build
  apt-get install libboost-dev libboost1.42-all-dev --install-recommends
+
cmake ../freeorion
 
+
make
==Ogre3D==
+
===Packages===
+
From Debian Squeeze and Ubuntu Lucid up there is no need to do next Ogre3D steps.
+
However Debian Lenny does not provide ogre-dev binary package in required version. One can be found from http://www.cazfi.net/deb or in [https://launchpad.net/~andrewfenn/+archive/ogredev Andrew Fenn]'s repository.
+
 
   
 
   
(sudo) add-apt-repository ppa:andrewfenn
+
To run freeorion you would then also need to create a link to the content directory, so
  (sudo) apt-get install libogre-dev
+
  ln -s ../freeorion/default .
and install new Ogre3D. If you prefer to compile Ogre3D yourself, read on.
+
  
===Ogre3D requirements===
+
and then
With current versions of Ogre it is probably best to follow [http://www.ogre3d.org/tikiwiki/tiki-index.php?page=CMake+Quick+Start+Guide&tikiversion=Linux the instructions here]
+
  ./freeorion
====Ubuntu and Debian====
+
Install Ogre3D requirements
+
  (sudo) apt-get install automake
+
(sudo) apt-get install libzzip-dev libfreeimage-dev x11proto-xf86vidmode-dev libxxf86vm-dev
+
(sudo) apt-get install libpcre3-dev libfreetype6-dev libxrandr-dev libxaw7-dev libmng-dev libglew1.5-dev libxt-dev
+
  
===Compiling===
+
If you have a multicore system with a lot of memory, you can substantially reduce compile time by running make with multiple threadsA minimum of 2-3 GB system memory per thread is recommendedSo for example, with a quadcore system having 12 GB or more of system memory, using
With current versions of Ogre it is probably best to follow [http://www.ogre3d.org/tikiwiki/tiki-index.php?page=CMake+Quick+Start+Guide&tikiversion=Linux the instructions here]
+
  make -j4
Previous Instructions
+
instead of simply
Download Ogre3D sources and unpack them. Supported compiler g++ and gcc versions is only version 4.3 or 4.4.
+
g++ --version
+
and
+
gcc --version
+
should return version 4.3 or 4.4
+
 
+
Compile Ogre3D with
+
aclocal
+
./bootstrap
+
./configure
+
make
+
 
+
and install with:
+
(sudo) make install
+
(sudo) ldconfig
+
 
+
==GiGi==
+
NOTE: As of r6016, this is no longer necessary. The Makefile generated by a simple cmake . will also build GiGi.
+
 
+
Before attempting to build FreeOrion you will first need to build and install the GiGi library, including GiGiOgre and the GiGiOgre OIS plugin. Before building GiGi you also need Ogre installed.
+
 
+
The GiGi source should be automatically downloaded from SVN along with the FreeOrion source code.
+
 
+
Change into the GiGi directory and build the library:
+
 
+
  cd freeorion/FreeOrion/GG
+
cmake -DBUILD_TUTORIALS=off -DBUILD_OGRE_DRIVER=ON -DBUILD_OGRE_OIS_PLUGIN=ON .
+
  make
+
(sudo) make install
+
(sudo) ldconfig
+
 
+
Add line as root
+
/usr/local/lib
+
to file /etc/ld.so.conf
+
 
+
==Bullet==
+
 
+
Bullet debian packets for some Debian/Ubuntu releases and architectures can be found from http://build.cazfi.net/deb/
+
 
+
Bullet sourcecode downloads are also available at https://code.google.com/p/bullet/downloads/list
+
 
+
===Building Bullet===
+
 
+
Install Bullet compilation requirements
+
(sudo) apt-get install freeglut3-dev
+
 
+
After downloading and unpacking downloaded bullet archive, compile it with:
+
cmake -D BUILD_SHARED_LIBS=true .
+
  make
+
and install with:
+
(sudo) make install
+
cd /usr/local/lib
+
(sudo) ln -s libBulletCollision.so libbulletcollision.so
+
(sudo) ln -s libBulletDynamics.so libbulletdynamics.so
+
(sudo) ln -s libLinearMath.so libbulletmath.so
+
(sudo) ldconfig
+
 
+
Symlinks libbulletcollision.so, libbulletdynamics.so and libbulletmath.so are required to create because bullet build system is inconsistent on different platforms.
+
 
+
==FreeOrion==
+
===Compiling FreeOrion===
+
Compile FreeOrion:
+
cd freeorion/FreeOrion
+
cmake .
+
 
  make
 
  make
If you have less than 8 GB of RAM, you might have errors during compiling relating to the compiler running out of heap space. In this case, try
+
can reduce elapsed compile time by nearly fourfold.  Depending on your machine specifics, total cpu time for compilation may be on the order of magnitude of 20-60+ minutes
make -j1
+
to specify that make should only use one thread, which should limit memory consumption. The flag
+
-fno-var-tracking
+
might also help.
+
  
 
===Updating FreeOrion===
 
===Updating FreeOrion===
 
When improvements have been made to FreeOrion, you should keep it up to date with:
 
When improvements have been made to FreeOrion, you should keep it up to date with:
  cd freeorion/FreeOrion
+
  cd freeorion
  svn update
+
  git pull
This should update GG and FreeOrion from subversion. After compiling and installing GG compile FreeOrion.
+
This should update GG and FreeOrion github.
  
 
===Clean After Dependency Changes===
 
===Clean After Dependency Changes===
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, such as Boost.  Do this in FreeOrion and GG directory:
+
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, such as Boost.  Do this in the top freeorion directory and GG, client and server directories:
 
  rm CMakeCache.txt
 
  rm CMakeCache.txt
make clean
 
 
==User stories==
 
*[[User:AndrewW/Gentoo|Gentoo - Updated]] (February 08, 2013, Updated: June 27, 2013)
 
*[[User:cazfi/SeparateTree|Building to separate directory tree]] (June 2, 2009, Updated October 4, 2012)
 
*[[User_talk:wheals/Fedora|Fedora 18]] (June 9, 2013)
 
 
==Compilation Errors==
 
 
 
===Cmake can't find libraries/dependencies===
 
If cmake is not able to find a library (e.g. Ogre, OIS, etc) that is installed, please see [http://www.freeorion.org/forum/viewtopic.php?f=24&t=4913 this thread]
 
 
===no matching function for call to 'swap(adobe::version_1::any_regular_t&, adobe::version_1::any_regular_t&)'===
 
*Upgrade compiler gcc and g++ at least to version 4.3.3 or
 
*Change line 734 of GG/adobe/any_regular.hpp from
 
 
swap(r, result);
 
 
to
 
 
std::swap(r, result);
 
 
  
 +
then again run cmake and make
  
 
==Runtime Errors==
 
==Runtime Errors==
Line 206: Line 93:
 
==IDE for development==
 
==IDE for development==
 
*Text editor and cmake with make to compile.
 
*Text editor and cmake with make to compile.
*Eclipse is open source multiplatform IDE and can be used to compile FreeOrion, but plugins to support subversion and python have to be installed. See howto [[Compile With Eclipse]].
 
  
 
==Debugging==
 
==Debugging==
 
===Adding debug symbols to binary===
 
===Adding debug symbols to binary===
 
Turn on debugging symbols on GG and FreeOrion with:
 
Turn on debugging symbols on GG and FreeOrion with:
  cmake -DBUILD_DEBUG=1 .
+
  cmake -D CMAKE_BUILD_TYPE=Debug ../freeorion
 
and then rebuild GG and FreeOrion.
 
and then rebuild GG and FreeOrion.
  
 
===backtrace===
 
===backtrace===
 
Install debugger gdb and run freeorion in window mode(not in fullscreen) with:
 
Install debugger gdb and run freeorion in window mode(not in fullscreen) with:
  gdb ./freeorion
+
  gdb -- ./freeorion
 
and after it starts gdb type
 
and after it starts gdb type
 
  run
 
  run
 
and wait until segfault occurs. Then to print backtrace type
 
and wait until segfault occurs. Then to print backtrace type
 
  bt full
 
  bt full

Revision as of 14:31, 18 May 2018

For the most up-to-date instructions we recommend you begin by consulting the build instructions in our repository. The information below may possibly add some helpful details, but is also at greater risk of being out of date.

Each linux distribution will come with varying components already installed, although some libraries may be older than the version required by FreeOrion. Hopefully the notes below will help to identify what is required for your particular distribution.


Compiler

Required compiler is gcc and g++ version 5.0 or above. cmake must be version 3.1 or later.

For anyone who is going to be doing dev work or otherwise experimenting with multiple different builds, ccache (probably available via your package manager) is very highly recommended, for speeding up recompilation. When having previously compiled FreeOrion in a different build directory, and now compiling FO for the first time in a new build directory to keep the executables distinct, without ccache the compiler will redo the entire compilation process, but with ccache the process can be sped up roughly five-fold or more.

Platform specifics

Ubuntu

This is a revision pass as of June 2015. You can check which version of a given package is provided by your Ubuntu release at this page To build gigi or FreeOrion you first need to install the following packages (using Synaptic or muon or apt-get) (you will need to have the Universe repository included):

  • build-essential
  • pkg-config
  • python2.7-dev (python 2.7.x, but not python3)
  • cmake
  • git
  • libfreetype6-dev
  • libglew-dev
  • libsdl2-dev
  • libvorbis-dev
  • libopenal-dev
  • libboost-all-dev

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

sudo apt-get install build-essential git pkg-config cmake libboost-all-dev libglew-dev
sudo apt-get install python2.7-dev libfreetype6-dev libsdl2-dev libvorbis-dev libopenal-dev

Boost (libboost-all-dev) will need to be at least 1.56+ (check here).

Debian

For building the latest stable release in debian follow the directions here: Download#Building_from_source_the_Debian_way For building the most recent test versions you might want to follow the portion of those instructions for dependencies and then follow the regular Linux build instructions to get and build the most recent test version. If you have a debian based distribution for which these instructions don't work for you, then use the Ubuntu instructions as a guideline. You may also need to remove sudo from all commands and run these commands under root(to login type su).

FreeOrion

Compiling FreeOrion

Compile FreeOrion: It is advisable (for some environments necessary) to make a separate build directory; apparently for many people (this make be related to cmake version) it is necessary that the build folder be entirely outside the source tree. So if starting in the directory within which the 'freeorion' source tree resides, then the commands would be

mkdir freeorion_build
cd freeorion_build
cmake ../freeorion
make

To run freeorion you would then also need to create a link to the content directory, so

ln -s ../freeorion/default .

and then

./freeorion

If you have a multicore system with a lot of memory, you can substantially reduce compile time by running make with multiple threads. A minimum of 2-3 GB system memory per thread is recommended. So for example, with a quadcore system having 12 GB or more of system memory, using

make -j4

instead of simply

make

can reduce elapsed compile time by nearly fourfold. Depending on your machine specifics, total cpu time for compilation may be on the order of magnitude of 20-60+ minutes

Updating FreeOrion

When improvements have been made to FreeOrion, you should keep it up to date with:

cd freeorion
git pull

This should update GG and FreeOrion github.

Clean After Dependency Changes

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, such as Boost. Do this in the top freeorion directory and GG, client and server directories:

rm CMakeCache.txt

then again run cmake and make

Runtime Errors

Segmentation Fault

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

$ ./freeorion
Segmentation fault
  • Be certain that currently installed driver for your graphic card supports OpenGL 2.0 or later
  • You might be mixing dependencies compiled with different versions of GCC or different optimization level for Ogre, GiGi and FreeOrion. See this post
  • You have graphic card which doesn't support shader model 3 or above(Nvidia 6600 and above have, some AMD HD series also). There are known problems with AMD drivers on Linux. In future there will be functional Gallium driver(r300g or r600g) in Mesa. These new drivers will be available probably in Ubuntu 11.04.

Video mode set failed: Couldn't find matching GLX visual

Your video mode is probably set to 16-bit instead of 32-bit, which is what FreeOrion defaults to. You need to either change your X server color depth to 32-bit, or edit the FreeOrion config file in ~/freeorion/config.xml and change color-depth from 32 to 16. You can also try the command line argement:

./freeorion --color-depth 16

IDE for development

  • Text editor and cmake with make to compile.

Debugging

Adding debug symbols to binary

Turn on debugging symbols on GG and FreeOrion with:

cmake -D CMAKE_BUILD_TYPE=Debug ../freeorion

and then rebuild GG and FreeOrion.

backtrace

Install debugger gdb and run freeorion in window mode(not in fullscreen) with:

gdb -- ./freeorion

and after it starts gdb type

run

and wait until segfault occurs. Then to print backtrace type

bt full