Skip to main content

构建说明 (Linux)

🌐 Build Instructions (Linux)

遵循以下指南,在 Linux 上构建 Electron 本身,以便创建自定义的 Electron 二进制文件。有关将应用代码与预构建的 Electron 二进制文件打包和分发的内容,请参阅 应用分发 指南。

🌐 Follow the guidelines below for building Electron itself on Linux, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the application distribution guide.

先决条件

🌐 Prerequisites

由于 Electron 依赖于 Chromium,Electron 的前置条件和依赖会随时间变化。Chromium 官方关于在 Linux 上构建的文档 提供了在 Linux 上构建 Chromium 的最新信息。一般来说,这些文档也可以用于在 Linux 上构建 Electron。

🌐 Due to Electron's dependency on Chromium, prerequisites and dependencies for Electron change over time. Chromium's documentation on building on Linux has up to date information for building Chromium on Linux. This documentation can generally be followed for building Electron on Linux as well.

此外,可以参考 Electron 的 Linux 依赖安装器 来获取 Electron 除 Chromium 通过 build/install-deps.sh 安装的依赖之外所需的当前依赖。

🌐 Additionally, Electron's Linux dependency installer can be referenced to get the current dependencies that Electron requires in addition to what Chromium installs via build/install-deps.sh.

交叉编译

🌐 Cross compilation

如果你想为 arm 目标构建,可以使用 Electron 的 Linux 依赖安装器 通过传递 --arm argument 来安装额外的依赖:

🌐 If you want to build for an arm target, you can use Electron's Linux dependency installer to install the additional dependencies by passing the --arm argument:

$ sudo install-deps.sh --arm

要为 arm 或其他目标进行交叉编译,你应该将 target_cpu 参数传递给 gn gen

🌐 And to cross-compile for arm or targets, you should pass the target_cpu parameter to gn gen:

$ gn gen out/Testing --args='import(...) target_cpu="arm"'

架构

🌐 Building

请参阅 构建说明:GN

🌐 See Build Instructions: GN

故障排除

🌐 Troubleshooting

加载共享库时出错:libtinfo.so.5

🌐 Error While Loading Shared Libraries: libtinfo.so.5

预构建的 clang 将尝试链接到 libtinfo.so.5。根据主机架构,创建到相应 libncurses 的符号链接:

🌐 Prebuilt clang will try to link to libtinfo.so.5. Depending on the host architecture, symlink to appropriate libncurses:

$ sudo ln -s /usr/lib/libncurses.so.5 /usr/lib/libtinfo.so.5

高级主题

🌐 Advanced topics

默认的构建配置针对主要的桌面 Linux 发行版。如需为特定的发行版或设备构建,以下信息可能对你有所帮助。

🌐 The default building configuration is targeted for major desktop Linux distributions. To build for a specific distribution or device, the following information may help you.

使用系统自带的 clang 而不是下载的 clang 二进制文件

🌐 Using system clang instead of downloaded clang binaries

默认情况下,Electron 使用 Chromium 项目提供的预构建 clang 二进制文件构建。如果出于某种原因你想使用系统中已安装的 clang 构建,可以在 GN 参数中指定 clang_base_path 参数。

🌐 By default Electron is built with prebuilt clang binaries provided by the Chromium project. If for some reason you want to build with the clang installed in your system, you can specify the clang_base_path argument in the GN args.

例如,如果你在 /usr/local/bin/clang 下安装了 clang

🌐 For example if you installed clang under /usr/local/bin/clang:

$ gn gen out/Testing --args='import("//electron/build/args/testing.gn") clang_base_path = "/usr/local/bin"'

使用除 clang 之外的编译器

🌐 Using compilers other than clang

不支持使用除 clang 之外的编译器构建 Electron。

🌐 Building Electron with compilers other than clang is not supported.