GN+NINJA环境搭建(MacOS Windows)

Ninja是一个专注于速度的小型构建系统,常与GN配合使用。GN是一个元构建系统,用于为Ninja生成构建文件。要安装Ninja,可以从官方网站下载二进制文件或通过包管理器安装。GN则需要自行编译。博客中提供了简单的使用示例,展示了如何用Ninja和GN构建并运行项目。GN类似于CMake,管理大型工程更为便捷。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

什么是ninja

科学上网速度快

Ninja is a small build system with a focus on speed. It differs from other build systems in two major respects: it is designed to have its input files generated by a higher-level build system, and it is designed to run builds as fast as possible.

什么是gn

科学上网速度快

GN is a meta-build system that generates build files for Ninja.

安装 ninja

You can download the Ninja binary or find it in your system’s package manager.

推荐使用包管理器安装省心又省力.

安装 gn

You can download the latest version of GN binary for Linux, macOS and Windows from Google’s build infrastructure (see “Versioning and distribution” below for how this is expected to work).

Alternatively, you can build GN from source with a C++17 compiler:

git clone https://gn.googlesource.com/gn
cd gn
python build/gen.py # --allow-warning if you want to build with warnings.
ninja -C out

推荐自行编译后把生成的二进制文件添加到系统变量中.

第一次

There is a simple example in examples/simple_build directory that is a good place to get started with the minimal configuration.

To build and run the simple example with the default gcc compiler:

cd examples/simple_build
../../out/gn gen -C out
ninja -C out
./out/hello
Hello, world

总结

gn对于ninja相当于cmake对于make.
利用ninja编译需要.ninja文件,直接编写也是可以的,但工具gn会更加方便的管理大型工程.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值