為 X11 進行編譯 (Linux, *BSD)¶
也參考
This page describes how to compile Linux editor and export template binaries from source. If you're looking to export your project to Linux instead, read Exporting for Linux.
系統需求¶
若要在 Linux 或其他各種 Unix 下進行編譯,必須滿足下列條件:
GCC 7+ 或 Clang 6+。
Python 3.5+。
SCons 3.0+ 建置系統。若使用預設為 Python 2 的發行版,或使用 3.1.2 版以前的 SCons,則必須更改 SCons 腳本檔的 Shebang (第一行) 為
#!/usr/bin/python3
來更改 SCons 使用的 Python 版本。可使用which scons
指令來找到 SCons 腳本的位置。pkg-config (用於偵測下方的相依性套件)。
X11, Xcursor, Xinerama, Xi 與 XRandR 開發函式庫。
MesaGL 開發函式庫。
ALSA 開發函式庫。
PulseAudio 開發函式庫。
可選 - libudev (使用
udev=yes
進行建置)。可選 - yasm (用於最佳化 WebM SIMD)。
用於各個發行版的單行安裝程式¶
Alpine Linux |
apk add scons pkgconf gcc g++ libx11-dev libxcursor-dev libxinerama-dev libxi-dev libxrandr-dev \
mesa-dev libexecinfo-dev eudev-dev alsa-lib-dev pulseaudio-dev
|
Arch Linux |
pacman -S --needed scons pkgconf gcc libxcursor libxinerama libxi libxrandr mesa glu libglvnd \
alsa-lib pulseaudio yasm
|
Debian / Ubuntu |
sudo apt-get install build-essential scons pkg-config libx11-dev libxcursor-dev libxinerama-dev \
libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libudev-dev libxi-dev libxrandr-dev yasm
|
Fedora |
sudo dnf install scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \
libXi-devel mesa-libGL-devel mesa-libGLU-devel alsa-lib-devel pulseaudio-libs-devel \
libudev-devel yasm gcc-c++ libstdc++-static libatomic-static
|
FreeBSD |
sudo pkg install py37-scons pkgconf xorg-libraries libXcursor libXrandr libXi xorgproto libGLU \
alsa-lib pulseaudio yasm
|
Gentoo |
emerge -an dev-util/scons x11-libs/libX11 x11-libs/libXcursor x11-libs/libXinerama x11-libs/libXi \
media-libs/mesa media-libs/glu media-libs/alsa-lib media-sound/pulseaudio dev-lang/yasm
|
Mageia |
urpmi scons task-c++-devel pkgconfig "pkgconfig(alsa)" "pkgconfig(glu)" "pkgconfig(libpulse)" \
"pkgconfig(udev)" "pkgconfig(x11)" "pkgconfig(xcursor)" "pkgconfig(xinerama)" "pkgconfig(xi)" \
"pkgconfig(xrandr)" yasm
|
OpenBSD |
pkg_add python scons llvm yasm
|
openSUSE |
sudo zypper install scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \
libXi-devel Mesa-libGL-devel alsa-devel libpulse-devel libudev-devel libGLU1 yasm
|
NetBSD |
pkg_add pkg-config py37-scons yasm
若要支援音訊,則可選擇性地安裝 |
Solus |
sudo eopkg install -c system.devel scons libxcursor-devel libxinerama-devel libxi-devel \
libxrandr-devel mesalib-devel libglu alsa-lib-devel pulseaudio-devel yasm
|
編譯¶
開啟終端機,移至 Godot 原始碼的根目錄然後輸入:
scons -j8 platform=x11
有關 -j
(jobs) 旗標的一個經驗法則是,最好設定為使用至少跟 CPU 核心數一樣多的執行緒數來編譯 Godot,也可以再多 1 至 2 個,不要超過即可。可以自由選擇是否要在本文下方提到的任意 SCons 指令中加上 -j
選項。
若沒有出現什麼問題的話,最終產生的二進位可執行檔會被放在「bin」子資料夾中。該執行檔包含了整個 Godot 遊戲引擎,且可不依賴任何相依性套件執行。執行該檔案會開啟專案管理員。
備註
若想使用 Clang 而不是 GCC 來編譯的話,請使用這個指令:
scons platform=x11 use_llvm=yes
在 OpenBSD 上似乎需要使用 Clang,否則無法正確建置字體。
備註
若是要為正式環境編譯 Godot,則可以通過加上 target=release_debug
SCons 選項來讓最終產生的可執行檔更小且更快速。
If you are compiling Godot with GCC, you can make the binary
even smaller and faster by adding the SCons option use_lto=yes
.
As link-time optimization is a memory-intensive process,
this will require about 7 GB of available RAM while compiling.
備註
若想在客製化建置上使用與 Godot 官方釋出版本不同的編輯器設定,可以通過在 bin/
資料夾中建立檔名為 ._sc_
或 _sc_
的檔案來開啟 Self-contained mode 。
編譯無周邊版本與伺服器版本¶
若要編譯用於以編輯器功能來自動化匯出專案的 無周邊 版本,請使用:
scons -j8 platform=server tools=yes target=release_debug
To compile a debug server build which can be used with remote debugging tools, use:
scons -j8 platform=server tools=no target=release_debug
若要編譯可執行專屬遊戲伺服器的 伺服器 版本,請使用:
scons -j8 platform=server tools=no target=release
建置匯出樣板¶
警告
Linux 二進位執行檔通常無法在比用來建置該執行檔還要舊的發行版上執行。若想提供能在多數發行版上執行的二進位執行檔,請使用較舊的發行版來建置,如 Ubuntu 16.04。可以使用虛擬機或容器來設定一個適合的建置環境。
若要建置 X11 (Linux, *BSD) 匯出樣板,請使用下列參數來執行建置系統:
(32 位元)
scons platform=x11 tools=no target=release bits=32
scons platform=x11 tools=no target=release_debug bits=32
(64 位元)
scons platform=x11 tools=no target=release bits=64
scons platform=x11 tools=no target=release_debug bits=64
請注意,可能無法為與目前宿主機環境不同的位元 (64/32) 進行交叉編譯時,有可能會需要 Chroot 環境。
要建立標準的匯出樣板,則必須將產生的檔案複製至:
$HOME/.local/share/godot/templates/[gd-version]/
並將這些檔案如下命名 (在 Godot 中,*BSD 被視為「Linux X11」):
linux_x11_32_debug
linux_x11_32_release
linux_x11_64_debug
linux_x11_64_release
但,若你正在撰寫客製化模組或自定 C++ 程式碼,則可能會需要在此將該二進位執行檔設定為自定匯出樣板:

這種情況下甚至不需要複製檔案,只需要將這些檔案參照到 Godot 原始碼目錄的 bin/
資料夾下即可。這樣下次建置時,就會自動參照到自定樣板。
使用 Clang 與 LLD 來更快速地開發¶
也可以使用 Clang 與 LLD 來建置 Godot。使用 Clang 與 LLD 比起預設的 GCC + GNU ld 有兩個好處:
LLD 與 GNU ld 或 gold 比起來,連結速度明顯快很多。這樣就可以迭代地更快。
Clang 比起 GCC,提供的錯誤訊息通常更有用。
要使用 Clang 與 LLD,請先使用發行版的套件管理員來安裝 Clang 與 lld
套件,然後使用下列 SCons 指令:
scons platform=x11 use_llvm=yes use_lld=yes
After the build is completed, a new binary with a .llvm
suffix will be
created in the bin/
folder.
雖然我們依然建議正式版本使用 GCC 來建置,因為 GCC 可以配合連結時期最佳化來編譯,產生的二進位執行檔也更小更快。
Using Pyston for faster development¶
You can use Pyston to run SCons. Pyston is a JIT-enabled implementation of the Python language (which SCons is written in). It is currently only compatible with Linux. Pyston can speed up incremental builds significantly, often by a factor between 1.5× and 2×. Pyston can be combined with Clang and LLD to get even faster builds.
Download the latest portable Pyston release.
Extract the portable
.tar.gz
to a set location, such as$HOME/.local/opt/pyston/
(create folders as needed).Use
cd
to reach the extracted Pyston folder from a terminal, then run./pyston -m pip install scons
to install SCons within Pyston.To make SCons via Pyston easier to run, create a symbolic link of its wrapper script to a location in your
PATH
environment variable:ln -s ~/.local/opt/pyston/bin/scons ~/.local/bin/pyston-scons
Instead of running
scons <build arguments>
, runpyston-scons <build arguments>
to compile Godot.
If you can't run pyston-scons
after creating the symbolic link,
make sure $HOME/.local/bin/
is part of your user's PATH
environment variable.