編寫“Hello World”程序
下方將展示如何在單板上運行第一個應(yīng)用程序,其中包括新建應(yīng)用程序、編譯、燒寫、運行等步驟,最終輸出“Hello World!”。
前提條件
已參考[創(chuàng)建工程并獲取源碼],創(chuàng)建Hi3516開發(fā)板的源碼工程。
鴻蒙開發(fā)指導(dǎo)文檔:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
示例目錄
示例完整目錄如下:HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
applications/sample/hello
│── BUILD.gn
└── src
└── helloworld.c
開發(fā)步驟
請在源碼目錄中通過以下步驟創(chuàng)建“Hello World”應(yīng)用程序。
新建目錄及源碼。
新建applications/sample/hello/src/helloworld.c目錄及文件,代碼如下所示,用戶可以自定義修改打印內(nèi)容(例如:修改OHOS為World)。當(dāng)前應(yīng)用程序可支持標(biāo)準(zhǔn)C及C++的代碼開發(fā)。#include < stdio.h > int main(int argc, char **argv) { printf("nn"); printf("nttHello OHOS!n"); printf("nnn"); return 0; }
新建編譯組織文件。
新建applications/sample/hello/BUILD.gn文件,內(nèi)容如下所示:import("http://build/lite/config/component/lite_component.gni") lite_component("hello-OHOS") { features = [ ":helloworld" ] } executable("helloworld") { output_name = "helloworld" sources = [ "src/helloworld.c" ] }
添加新組件。
修改文件build/lite/components/applications.json,添加組件hello_world_app的配置,如下所示為applications.json文件片段,"##start##"和"##end##"之間為新增配置("##start##"和"##end##"僅用來標(biāo)識位置,添加完配置后刪除這兩行):說明: 本章節(jié)操作是以O(shè)penHarmony-v3.1-Release版本為例進(jìn)行操作的,該版本中,組件配置文件為build/lite/components/applications.json;若源碼版本大于等于OpenHarmony 3.2 Beta2時,組件配置文件為build/lite/components/communication.json。
{ "components": [ { "component": "camera_sample_communication", "description": "Communication related samples.", "optional": "true", "dirs": [ "applications/sample/camera/communication" ], "targets": [ "http://applications/sample/camera/communication:sample" ], "rom": "", "ram": "", "output": [], "adapted_kernel": [ "liteos_a" ], "features": [], "deps": { "components": [], "third_party": [] } }, ##start## { "component": "hello_world_app", "description": "hello world samples.", "optional": "true", "dirs": [ "applications/sample/hello" ], "targets": [ "http://applications/sample/hello:hello-OHOS" ], "rom": "", "ram": "", "output": [], "adapted_kernel": [ "liteos_a" ], "features": [], "deps": { "components": [], "third_party": [] } }, ##end## { "component": "camera_sample_app", "description": "Camera related samples.", "optional": "true", "dirs": [ "applications/sample/camera/launcher", "applications/sample/camera/cameraApp", "applications/sample/camera/setting", "applications/sample/camera/gallery", "applications/sample/camera/media" ],
修改單板配置文件。
修改文件vendor/hisilicon/hispark_taurus/config.json,新增hello_world_app組件的條目,如下所示代碼片段為applications子系統(tǒng)配置,"##start##"和"##end##"之間為新增條目("##start##"和"##end##"僅用來標(biāo)識位置,添加完配置后刪除這兩行):{ "subsystem": "applications", "components": [ { "component": "camera_sample_app", "features":[] }, { "component": "camera_sample_ai", "features":[] }, ##start## { "component": "hello_world_app", "features":[] }, ##end## { "component": "camera_screensaver_app", "features":[] } ] },
審核編輯 黃宇
-
開發(fā)板
+關(guān)注
關(guān)注
25文章
5031瀏覽量
97367 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2337瀏覽量
42801 -
HarmonyOS
+關(guān)注
關(guān)注
79文章
1973瀏覽量
30134 -
OpenHarmony
+關(guān)注
關(guān)注
25文章
3713瀏覽量
16251
發(fā)布評論請先 登錄
相關(guān)推薦
評論