README.md
1# 使用指南
2
3## 简介
4
5包括系统提供的c/c++接口库文件,编译工具链,工具和接口描述文档。
6
7## 目录结构
8
9├── build **编译框架**
10│ ├── config
11│ └── toolchain
12├── doc **native api接口描述文档**
13├── gcc **编译工具链**
14│ ├── arm-linux-ohoseabi -> arm-linux-musleabi
15│ ├── arm-linux-musleabi
16│ ├── bin
17│ ├── host_bin
18│ ├── lib
19│ ├── libexec
20│ ├── runtime_musl
21│ └── target
22├── prebuilts **构建工具**
23│ └── build-tools
24├── sample **用户编译样例**
25│ ├── include
26│ └── src
27└── sysroot **Native API**
28 └── usr
29
30## 编译框架
31
32### 编译命令
33
34编译使用gn构建系统,在根目录执行:`python build.py`即可启动编译。支持的命令如下:
35
36**build:** `python build.py ` 或 ``python build.py build`
37
38**clean:** `python build.py clean`
39
40**debug/release**:`python build.py -v debug/release`
41
42debug和release版本的区别:
43
44debug版本:-g
45
46release版本:-O2 + strip符号表
47
48### 默认编译选项
49
501、安全编译选项:-fstack-protector-all,PIE,PIC,_FORTIFY_SOURCE=2,-Wl,-z,now,-Wl,-z,relro,-Wl,-z,noexecstack
51
522、告警级别:-Werror
53
54### 应用编译示例
55
561、创建应用目录,并在目录下创建BUILD.gn:
57
58```
59# Copyright (c) 2020 Huawei Device Co., Ltd.
60# Licensed under the Apache License, Version 2.0 (the "License");
61# you may not use this file except in compliance with the License.
62# You may obtain a copy of the License at
63#
64# http://www.apache.org/licenses/LICENSE-2.0
65#
66# Unless required by applicable law or agreed to in writing, software
67# distributed under the License is distributed on an "AS IS" BASIS,
68# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69# See the License for the specific language governing permissions and
70# limitations under the License.
71
72static_library("hello_world") { # 应用库文件target,也可是shared_library
73 sources = [
74 "src/hello_world.c",
75 ]
76
77 include_dirs = [
78 "include",
79 ]
80}
81
82executable("sample") { # 应用可执行文件target
83 ldflags = [
84 "-lsys_parameter", # 应用需要使用的库
85 "-lsec_shared"
86 ]
87 deps = [
88 ":hello_world",
89 ]
90}
91
92```
93
942、将sample加入到编译入口,编译入口为根目录下的BUILD.gn:
95
96```
97# Copyright (c) 2020 Huawei Device Co., Ltd.
98# Licensed under the Apache License, Version 2.0 (the "License");
99# you may not use this file except in compliance with the License.
100# You may obtain a copy of the License at
101#
102# http://www.apache.org/licenses/LICENSE-2.0
103#
104# Unless required by applicable law or agreed to in writing, software
105# distributed under the License is distributed on an "AS IS" BASIS,
106# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
107# See the License for the specific language governing permissions and
108# limitations under the License.
109
110import("//build/toolchain/${ohos_build_compiler}.gni")
111
112group("ohos") {
113 deps = []
114 if (target_os == "ohos") {
115 deps += [
116 "//sample" # 新加的应用
117 ]
118 }
119}
120```
121
1223、编译输出:out/bin
123
124## 烧录和运行
125
1261、请先烧录内核和文件系统
127
1282、将应用程序nfs或者tftp到usr/bin目录下, 运行即可
129