Skip to content

Building OpenRCT2 on Linux

Michael Steenbeek edited this page Apr 15, 2024 · 125 revisions

OpenRCT2 can only be built on little-endian architectures for now.

This page tells you how to build the project. For instructions on how to get assets and run it check installation on Linux and macOS.

Required Packages (General)

To build natively on Linux, you will need a set of libraries set up. Since most distributions come with a package manager, we expect you to use that. Required libraries include:

Package Note(s)
gccorclang gcc >= 7.1 or clang >= 8.0.0 (C++17 support needed)
sdl2 Only for UI client.
freetype Can be disabled.
fontconfig Can be disabled.
libzip >= 1.0
libpng >= 1.2
speexdsp Only for UI client.
curl only if building with http support.
openssl >= 1.0; Only if building with multiplayer support.
icu >= 59.0
zlib
gl Commonly provided by Mesa or GPU vendors; only for UI client, can be disabled.
duktape Shipped with the code. Not used if scripting is disabled.
cmake
nlohmann-json >= 3.6.0
Google Benchmark Optional.
libvorbis
libogg
flac

Additionally, you can add support for Discord's Rich Presence API by cloning https://github.com/discordapp/discord-rpc into the root clone directory. Do note discord-rpc requires rapidjson, which don't bother fixing their bugs and you may need the hackish workaround: janisozaur/rapidjson/commit/20f8604ee6cd078c1cb2346148c69c0c2c160db2

APT (Debian, Ubuntu)

The exact package names will differ from distribution to distribution, but here's a short list of the common ones:

sudo apt-get install --no-install-recommends -y cmake libsdl2-dev libicu-dev \
    gcc pkg-config libspeex-dev libspeexdsp-dev libcurl4-openssl-dev \
    libcrypto++-dev libfontconfig1-dev libfreetype6-dev libpng-dev libssl-dev libzip-dev \
    build-essential make nlohmann-json3-dev libbenchmark-dev \
    libflac-dev libvorbis-dev

This listing should work on Debian and Ubuntu.

pacman (Arch)

Install dependencies:

sudo pacman -S base-devel sdl2 curl nlohmann-json speexdsp fontconfig libpng openssl libzip icu cmake ninja flac libvorbis

DNF (Fedora):

Run the following for dependencies, then proceed with Linux build instructions.

sudo dnf install gcc gcc-c++ json-devel \
    openssl-devel SDL2-devel libicu-devel \
    speexdsp-devel libcurl-devel \
    cmake fontconfig-devel freetype-devel \
    libpng-devel libzip-devel mesa-libGL-devel \
    libvorbis-devel flac-devel

Gentoo

This section is outdated and needs an update to reflect we can now build for x86_64 and other little-endian platforms.

This install requires either plain x86 system or amd64 with multilib enabled.

With regular x86 system, you just need to configure the sources with cmake (see below) and compile.

On amd64 you first need to enable multilib and then add abi_x86_32 to at least following libraries:

# cat /etc/portage/package.use/abi_x86_32
## Please note that this library list may be incomplete due to USE flag differences
dev-cpp/nlohmann_json   abi_x86_32
media-libs/libsdl2      abi_x86_32
media-libs/sdl2-mixer   abi_x86_32
media-libs/speex        abi_x86_32
net-misc/curl           abi_x86_32

Then you need to emerge required libraries and in case portage gives shows some dependency issues, fix up the libraries with missing abi_x86_32 flags by adding them to the list above.

openSUSE

Install dependencies:

sudo zypper in SDL2-devel fontconfig libzip5 libzip-devel libpng16-devel libicu-devel speexdsp-devel curl libcurl-devel nlohmann_json openssl openssl-devel glibc zlib cmake gcc gcc-c++ fontconfig-devel

Notes for Leap

Some old Leap versions use an old version of gcc by default, while OpenRCT2 needs gcc7 or later. You'll need to fix the symlinks for g++ and c++ to point to g++-7. Leap 15 uses gcc7 by default.

Alpine Linux

Install dependencies:

apk add git gcc g++ make cmake libzip-dev curl-dev nlohmann-json sdl2-dev fontconfig-dev fts-dev icu-dev speexdsp-dev

(Dependency fts may not be required in the future, see #5520) (You may wish to install Zenity or KDialog, see #5521)

Solus

Install these dependencies then build as normal:

sudo eopkg install sdl2-devel curl-devel libspeex-devel fontconfig-devel libpng-devel openssl-devel libzip-devel libicu-devel mesalib-devel nlohmann-json

Compiling

mkdir build && cd build
cmake .. # Remember to set your build flags, e.g. -DCMAKE_BUILD_TYPE=RelWithDebInfo
make

This will generate a openrct2 binary in the build directory. To run you have two options: make install or running it locally.

make install

make install will download required resources (json objects, title sequences) and installs openrct2 under /usr/local by default, but DESTDIR will be properly honoured (see below).

Running it from the build directory

Alternatively you can install the required resources manually so can launch openrct2 from the project directory. You need a functional data directory next to the current working directory when you start openrct2.

An easy way to generate such a data directory is by leveraging make install. Type the following in the build directory:

DESTDIR=. make install

Alternatively you can install these assets yourself. The following needs to satisfied:

$XDG_CONFIG_HOME/OpenRCT2/ (or ~/.config/OpenRCT2/ in its absence) has to have config.ini with game_path set to an RCT install. openrct2 will ask you for this directory when it first starts.

Keep in mind you can symlink stuff and that filesystems are case sensitive!

Alternatively you can specify the data directory like this:

./openrct2 --openrct-data-path=../data

OR

Just symlink the data directory in the current build directory, which is the easiest approach for development

ln -s ../data data

Clang

Building with clang works the same way as building with GCC, you just need to change the CXX environment variable. Keep in mind, that you need to have an empty build directory as cmake will not switch compilers after it has already generated a Makefile.

mkdir build && cd build
export CXX=$(which clang++) # OpenRCT2 is purely a C++ project, there's no need to set CC
cmake ..
make

See the optimization note above.

Ninja

You can switch from Make to Ninja, if you prefer:

mkdir build && cd build
cmake .. -G Ninja # Any other arguments you want, for example -DCMAKE_BUILD_TYPE=RelWithDebInfo
ninja # No need to specify parallel, it does that automatically
DESTDIR=. ninja install

discord-rpc

#6658 added support for discord-rpc, Discord's Rich Presence client library. It gets automatically picked up when cloned into the root of repository.

Docker

Docker is a nice way of doing things when you have problems installing all the dependencies or just want to test on clean system. Docker containers are ephemeral snapshots of a specified system (described via Dockerfile), where you can run your commands.

Let's see example from our current build.sh:

PARENT=`readlink -f ../`
chmod a+rwx `pwd`
chmod g+s `pwd`
docker run -u travis -v $PARENT:/work/openrct2 -w /work/openrct2/build -i -t openrct2/openrct2:32bit-only bash -ec "cmake ../ $OPENRCT2_CMAKE_OPTS && make"

This runs the specified command (bash -ec "cmake ../ $OPENRCT2_CMAKE_OPTS && make") interactively as a travis user dockerfiles/32bit/Dockerfile#L7, having previously mounted your local (host's) $PARENT as container's /work/openrct2, and will use /work/openrct2/build as cwd.

You may want to update mountpoints so you can reflect your local paths easily, especially when debugging.

Apart from contents of mounted volumes, all results of commands you executed in this container will be gone after it exits.

MinGW

To build using mingw toolchain, you will need the toolchain itself, cmake and some basic system utilities you likely already have (bash, unzip, wget, sha256sum).

The install.sh script should largely handle that case. Said script should also download latest version of zip including precompiled libraries we use in the project and copy extracted contents to places where you could expect to find them.

Keep in mind we have no capacity to test the script thoroughly and while some caution and code review has been applied, it's possible that the script doesn't work properly or even breaks things. We welcome any patch to solve these kinds of problems.

Study CMakeLists.txt file to see what options are there, but in most basic case you should be fine with just

export OPENRCT2_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows

build.sh is roughly just a fancy wrapper for

cmake -DCMAKE_BUILD_TYPE=Debug $OPENRCT2_CMAKE_OPTS ..
make

You can either use the script or invoke make directly.

To launch the game, you would simply start openrct2.exe using wine or Windows.

Clone this wiki locally