跟着小白一起学鸿蒙之第一个OpenHarmony程序
source link: https://www.51cto.com/article/717390.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
跟着小白一起学鸿蒙之第一个OpenHarmony程序
今天我们来熟悉下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!#
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK