Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
build/ | 12-May-2024 | - | 738 | 633 | ||
doc/ | 12-May-2024 | - | 4,788 | 3,691 | ||
sample/ | 12-May-2024 | - | 51 | 30 | ||
BUILD.gn | D | 12-May-2024 | 5.5 KiB | 152 | 144 | |
README.md | D | 12-May-2024 | 3.5 KiB | 128 | 96 | |
archive_ndk.py | D | 12-May-2024 | 2.1 KiB | 74 | 46 | |
ndk.gni | D | 12-May-2024 | 3.9 KiB | 154 | 138 |
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│ └── target 21├── prebuilts **构建工具** 22│ └── build-tools 23├── sample **用户编译样例** 24│ ├── include 25│ └── src 26└── sysroot **Native API** 27 └── usr 28 29## 编译框架 30 31### 编译命令 32 33编译使用gn构建系统,在根目录执行:`python build.py`即可启动编译。支持的命令如下: 34 35**build:** `python build.py ` 或 ``python build.py build` 36 37**clean:** `python build.py clean` 38 39**debug/release**:`python build.py -v debug/release` 40 41debug和release版本的区别: 42 43debug版本:-g 44 45release版本:-O2 + strip符号表 46 47### 默认编译选项 48 491、安全编译选项:-fstack-protector-all,PIE,PIC,_FORTIFY_SOURCE=2,-Wl,-z,now,-Wl,-z,relro,-Wl,-z,noexecstack 50 512、告警级别:-Werror 52 53### 应用编译示例 54 551、创建应用目录,并在目录下创建BUILD.gn: 56 57``` 58# Copyright (c) 2020 Huawei Device Co., Ltd. 59# Licensed under the Apache License, Version 2.0 (the "License"); 60# you may not use this file except in compliance with the License. 61# You may obtain a copy of the License at 62# 63# http://www.apache.org/licenses/LICENSE-2.0 64# 65# Unless required by applicable law or agreed to in writing, software 66# distributed under the License is distributed on an "AS IS" BASIS, 67# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 68# See the License for the specific language governing permissions and 69# limitations under the License. 70 71static_library("hello_world") { # 应用库文件target,也可是shared_library 72 sources = [ 73 "src/hello_world.c", 74 ] 75 76 include_dirs = [ 77 "include", 78 ] 79} 80 81executable("sample") { # 应用可执行文件target 82 ldflags = [ 83 "-lsys_parameter", # 应用需要使用的库 84 "-lsec_shared" 85 ] 86 deps = [ 87 ":hello_world", 88 ] 89} 90 91``` 92 932、将sample加入到编译入口,编译入口为根目录下的BUILD.gn: 94 95``` 96# Copyright (c) 2020 Huawei Device Co., Ltd. 97# Licensed under the Apache License, Version 2.0 (the "License"); 98# you may not use this file except in compliance with the License. 99# You may obtain a copy of the License at 100# 101# http://www.apache.org/licenses/LICENSE-2.0 102# 103# Unless required by applicable law or agreed to in writing, software 104# distributed under the License is distributed on an "AS IS" BASIS, 105# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 106# See the License for the specific language governing permissions and 107# limitations under the License. 108 109import("//build/toolchain/${ohos_build_compiler}.gni") 110 111group("ohos") { 112 deps = [] 113 if (target_os == "ohos") { 114 deps += [ 115 "//sample" # 新加的应用 116 ] 117 } 118} 119``` 120 1213、编译输出:out/bin 122 123## 烧录和运行 124 1251、请先烧录内核和文件系统 126 1272、将应用程序nfs或者tftp到usr/bin目录下, 运行即可 128