了解更多开源请访问:开源基础软件社区https://ost.51cto.com今天我们来熟悉一下OpenHarmony的编译框架以及如何开发我们自己的HelloWord程序。OpenHarmony的编译过程分析图介绍LRbuild.sh-->build.py-->hb-->gnhb-->ninjahb-->clang术语gn:生成ninja工具,在out目录下生成ninja编译文件*.ninja,文件位置在prebuilts/build-tools/linux-x86目录下。$./gn--helpCommands(键入“gnhelp”以获得更多帮助):analyze:分析哪些目标受文件列表的影响。args:显示或配置构建声明的参数。check:检查标头依赖性。clean:清理输出目录。desc:显示有关目标或配置的大量有见地的信息。格式:格式化.gn文件。gen:生成忍者文件。帮助:按照您的想法行事。ls:列出匹配的目标。meta:列出目标元数据收集结果。path:查找两个目标之间的路径。refs:Findstuffreferencedatargetorfile.……ninja:构建工具,根据生成的*.ninja文件进行编译构建,文件位置在prebuilts/build-tools/linux-x86目录里。./ninja--helpusage:ninja[options][targets...]如果未指定目标,则构建“默认”目标(参见手册)。options:--versionprintninjaversion("1.10.1")-v,--verbose在构建时显示所有命令行-CDIR在执行任何其他操作之前更改为DIR-fFILE指定输入构建文件[default=build.ninja]-jN并行运行N个作业(0表示无限)[default=10onthissystem]-kNkeepgoinguntilNjobsfail(0meansinfinity)[default=1]-lN如果平均负载大于N,则不启动新作业-ndryrun(不运行命令但表现得好像他们成功了一样)-dMODE启用调试(使用“-dlist”列出模式)-tTOOL运行子工具(使用“-tlist”列出子工具)终止顶层选项;furtherflagsarepassedtothetool-wFLAGadjustwarnings(use'-wlist'tolistwarnings)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",]}//Addednewapplicationohos_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=trueif(is_standard_system){deps=["webGL:webGL_hap_test","windowStage:ActsWindowStageTest","windowstandard:window_hap_test","//third_party/libuv:helloworld",#importhelloworld程序编译]}else{deps=["appaccount:appaccount_hap","osaccount:osaccount_hap",]}}源码根目录执行:./build.sh--product-namerk3568源码根目录执行:./build.sh--product-namerk3568--gn-argsbuild_xts=true--build-target"acts"--gn-argsis_standard_system=true5.使用编译后生成的第三方库验证程序helloworld。runtest库文件会输出helloworld,路径为:out/rk3568/common/common。~/oh32/out/rk3568/common/common$lslibclibimagePixelmap.solibnativerender.solibsqlite.z.solibteststring.solibusb_shared.z.sohelloworld使用方法如下:1.复制helloworld到板子hdc_std.exe文件发送helloworld/data/local/tmp//2.登录到开发板并运行helloworld。如果第一次需要给权限,PC端:hdc_std.exeshell板子:cd/data/local/tmp板子:chmod+xhelloworld板子:./helloworld结果:#./helloworldhelloworld!#了解更多关于开源,请访问:开源基础软件社区https://ost.51cto.com。