跟着小白一起学鸿蒙之第一个OpenHarmony程序
2023-02-25 18:06:21 时间
今天我们来熟悉下OpenHarmony的编译框架和如果自己开发一个HelloWord程序。
简介
OpenHarmony的编译过程分析
graph LR
build.sh --> build.py --> hb --> gn
hb --> ninja
hb --> clang
名词解释
gn: generate ninja工具,在out目录下生成ninja编译文件*.ninja,文件位置在prebuilts/build-tools/linux-x86目录里。
$ ./gn --help
Commands (type "gn help <command>" for more help):
analyze: Analyze which targets are affected by a list of files.
args: Display or configure arguments declared by the build.
check: Check header dependencies.
clean: Cleans the output directory.
desc: Show lots of insightful information about a target or config.
format: Format .gn files.
gen: Generate ninja files.
help: Does what you think.
ls: List matching targets.
meta: List target metadata collection results.
path: Find paths between two targets.
refs: Find stuff referencing a target or file.
……
ninja:构建工具,根据gn生成的*.ninja文件进行编译构建,文件位置在prebuilts/build-tools/linux-x86目录里。
./ninja --help
usage: ninja [options] [targets...]
if targets are unspecified, builds the 'default' target (see manual).
options:
--version print ninja version ("1.10.1")
-v, --verbose show all command lines while building
-C DIR change to DIR before doing anything else
-f FILE specify input build file [default=build.ninja]
-j N run N jobs in parallel (0 means infinity) [default=10 on this system]
-k N keep going until N jobs fail (0 means infinity) [default=1]
-l N do not start new jobs if the load average is greater than N
-n dry run (don't run commands but act like they succeeded)
-d MODE enable debugging (use '-d list' to list modes)
-t TOOL run a subtool (use '-t list' to list subtools)
terminates toplevel options; further flags are passed to the tool
-w FLAG adjust warnings (use '-w list' to list warnings)
clang:编译器,同gcc兼容。
1、查看.gn并增加应用输出
路径为:oh32/third_party/libuv/BUILD.gn,找到如下位置增加。
//静态库
ohos_static_library("uv_static") {
deps = [ ":libuv_source" ]
public_configs = [ ":libuv_config" ]
subsystem_name = "thirdparty"
part_name = "libuv"
}
//动态库
ohos_shared_library("uv") {
deps = [ ":libuv_source" ]
public_configs = [ ":libuv_config" ]
subsystem_name = "thirdparty"
part_name = "libuv"
if (is_ohos) {
output_extension = "so"
}
install_images = [
"system",
"updater",
]
}
//增加的新应用
ohos_executable("helloworld") {
sources = [ "helloword.c",]
}
2、增加helloworld.c
在oh32/third_party/libuv目录下增加helloworld.c。
3、增加helloworld编译生成的入口
在test/xts/acts/graphic/BUILD.gn里增加deps,如下:
import("//build/ohos_var.gni")
group("graphic") {
testonly = true
if (is_standard_system) {
deps = [
"webGL:webGL_hap_test",
"windowStage:ActsWindowStageTest",
"windowstandard:window_hap_test",
"//third_party/libuv:helloworld", #引入helloworld程序编译
]
} else {
deps = [
"appaccount:appaccount_hap",
"osaccount:osaccount_hap",
]
}
}
源码根目录执行:
./build.sh --product-name rk3568
源码根目录执行:
./build.sh --product-name rk3568 --gn-args build_xts=true --build-target "acts" --gn-args is_standard_system=true
5、编译完成后生成的第三方库验证程序helloworld使用流程
runtest库文件会输出helloworld,路径为:out/rk3568/common/common。
~/oh32/out/rk3568/common/common$ ls
libc libimagePixelmap.so libnativerender.so libsqlite.z.so libteststring.so libusb_shared.z.so helloworld
使用方式如下:
1. 拷贝helloworld到板子上
hdc_std.exe file send helloworld /data/local/tmp
//2. 登录板子,运行helloworld,如果第一次需要给权限
pc端:hdc_std.exe shell
板子:cd /data/local/tmp
板子:chmod +x helloworld
板子:./helloworld
结果:
#./helloworld
hello world!#
相关文章
- 火山引擎云原生大数据在金融行业的实践
- OpenHarmony富设备移植指南(二)—从postmarketOS获取移植资源
- 《数据成熟度指数》报告:64%的企业领袖认为大多数员工“不懂数据”
- OpenHarmony 小型系统兼容性测试指南
- 肯睿中国(Cloudera):2023年企业数字战略三大趋势预测
- 适用于 Linux 的十大命令行游戏
- GNOME 截图工具的新旧截图方式
- System76 即将推出的 COSMIC 桌面正在酝酿大变化
- 2GB 内存 8GB 存储即可流畅运行,Windows 11 极致精简版系统 Tiny11 发布
- 迎接 ecode:一个即将推出的具有全新图形用户界面框架的现代、轻量级代码编辑器
- loongarch架构介绍(三)—地址翻译
- Go 语言怎么解决编译器错误“err is shadowed during return”?
- 敏捷:可能被开发人员遗忘的部分
- Denodo预测2023年数据管理和分析的未来
- 利用数据推动可持续发展
- 在 Vue3 中实现 React 原生 Hooks(useState、useEffect),深入理解 React Hooks 的
- 七步走!做出高质量的数据分析项目
- 谷歌正增强 Chrome 浏览器的画中画功能:可定制显示“点赞”等按钮
- 通过 ssh 与远程服务器之间传输文件的几种方法
- 微前端架构的几种技术选型