当前位置: 首页 > news >正文

GN ninja 工程化构建例程

请添加图片描述

文章目录

  • 1. 前言✨
  • 2. 工程实例🚩
    • 2.1 工程目录结构
    • 2.2 工程顶层.gn文件
    • 2.3 工具链配置.gn文件
    • 2.4 编译配置.gn文件
    • 2.5 编译目标配置.gn文件
    • 2.6 工程接口文件
    • 2.7 动态库编译.gn文件
    • 2.8 动态库源文件
    • 2.9 静态库编译.gn文件
    • 2.10 静态库源文件
    • 2.11 主程序编译.gn文件
    • 2.12 主程序源文件
    • 2.13 工程顶层.gn文件
  • 3. 编译&测试
  • 参考


1. 前言✨

本文通过一个简单的C语言工程构建实例,主要描述通过GN和ninjia如何构建、编译。

各位小伙伴,如果你是刚接触GN、ninja构建,这个实例工程非常适合你参考、学习,该实例包括静态库、动态库的编译、链接,还有对编译工具链的配置,编译输出的配置等,如果对你有帮助,请点赞👍👍👍、转发,评论&交流😊。💐💐💐🎉🎉🎉


2. 工程实例🚩

2.1 工程目录结构

.
├── BUILD.gn
├── README.md
├── build
│   ├── BUILD.gn
│   ├── BUILDCONFIG.gn
│   └── toolchains
│       └── BUILD.gn
├── include
│   └── utils.h
├── lib
│   ├── shared
│   │   ├── BUILD.gn
│   │   └── dlib.c
│   └── static
│       ├── BUILD.gn
│       └── slib.c
├── out
│   └── Default
│       ├── args.gn
│       ├── build.ninja
│       ├── build.ninja.d
│       ├── build.ninja.stamp
│       ├── libshared.so
│       ├── main
│       ├── obj
│       └── toolchain.ninja
├── src
│   └── main
│       ├── BUILD.gn
│       └── main.c
└── third_party13 directories, 19 files

2.2 工程顶层.gn文件

BUILD.gn

# 顶层group定义
group("all") {deps = ["//lib/static","//lib/shared","//src/main"]
}

2.3 工具链配置.gn文件

build/toolchains/BUILD.gn

# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.toolchain("gcc") {tool("cc") {depfile = "{{output}}.d"command = "gcc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"depsformat = "gcc"description = "CC {{output}}"outputs = ["{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",]}tool("cxx") {depfile = "{{output}}.d"command = "g++ -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"depsformat = "gcc"description = "CXX {{output}}"outputs = ["{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",]}tool("alink") {rspfile = "{{output}}.rsp"command =

相关文章:

  • yarn的三大组件及各自的作用
  • 进阶篇|CAN FD 与性能优化
  • uboot下读取ubifs分区的方法
  • leetcode刷题日记——单词规律
  • webgl入门实例-11模型矩阵 (Model Matrix)基本概念
  • Unity粒子特效打包后不显示
  • FP16、FP32 及全系列浮点格式全解析:从半精度到四倍精度
  • IDEA 2025.1更新-AI助手试用和第三方模型集成方案
  • 2025年GitHub平台上的十大开源MCP服务器汇总分析
  • 【AI飞】AutoIT入门七(实战):python操控autoit解决csf视频批量转换(有点难,AI都不会)
  • 如何下载适用于Docker环境的Google Chrome浏览器【镜像使用方法】
  • RT-Thread RTThread studio 初使用
  • osgb和obj格式互转
  • 计算机视觉---相机标定
  • Oracle之数据库对象加连表查询
  • 前端 实现文字打字效果(仿AI)
  • 三维点拟合直线ransac c++
  • C/C++中获取或处理时间节点方法
  • UWP特性分析
  • 软件招标评审模板
  • 最高检发布知识产权检察白皮书,“知识产权检察厅”同日亮相
  • 人民日报评“我愿意跟他挨着”:城市要善待奋斗者,惩治作恶者
  • 上海农房翻建为何难?基层盼政策适度松动
  • 文化中国行|1500年水镇枫泾有座丁聪美术馆
  • 美关税政策冲击本土车企:福特7月涨价,通用汽车盈利预期下调
  • 俄罗斯与乌克兰互换246名在押人员