文章目錄
- 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 =