編寫“Hello World”程序
下方將通過(guò)修改源碼的方式展示如何編寫簡(jiǎn)單程序,輸出“Hello world”。請(qǐng)?jiān)?a href="http://www.delux-kingway.cn/soft/special/" target="_blank">下載的源碼目錄中進(jìn)行下述操作。
- 確定目錄結(jié)構(gòu)。
開發(fā)者編寫業(yè)務(wù)時(shí),務(wù)必先在./applications/sample/wifi-iot/app路徑下新建一個(gè)目錄(或一套目錄結(jié)構(gòu)),用于存放業(yè)務(wù)源碼文件。
例如:在app下新增業(yè)務(wù)my_first_app,其中hello_world.c為業(yè)務(wù)代碼,BUILD.gn為編譯腳本,具體規(guī)劃目錄結(jié)構(gòu)如下:. └── applications └── sample └── wifi-iot └── app └── my_first_app │── hello_world.c └── BUILD.gn
鴻蒙開發(fā)指導(dǎo)文檔:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
編寫業(yè)務(wù)代碼。
新建./applications/sample/wifi-iot/app/my_first_app下的hello_world.c文件,在hello_world.c中新建業(yè)務(wù)入口函數(shù)HelloWorld,并實(shí)現(xiàn)業(yè)務(wù)邏輯。并在代碼最下方,使用OpenHarmony啟動(dòng)恢復(fù)模塊接口SYS_RUN()啟動(dòng)業(yè)務(wù)。(SYS_RUN定義在ohos_init.h文件中)#include < stdio.h > #include "ohos_init.h" #include "ohos_types.h" void HelloWorld(void) { printf("[DEMO] Hello world.n"); } SYS_RUN(HelloWorld);
編寫用于將業(yè)務(wù)構(gòu)建成靜態(tài)庫(kù)的BUILD.gn文件。
新建./applications/sample/wifi-iot/app/my_first_app下的BUILD.gn文件,并完成如下配置。
如步驟1所述,BUILD.gn文件由三部分內(nèi)容(目標(biāo)、源文件、頭文件路徑)構(gòu)成,需由開發(fā)者完成填寫。static_library("myapp") { sources = [ "hello_world.c" ] include_dirs = [ "http://utils/native/lite/include" ] }
- static_library中指定業(yè)務(wù)模塊的編譯結(jié)果,為靜態(tài)庫(kù)文件libmyapp.a,開發(fā)者根據(jù)實(shí)際情況完成填寫。
- sources中指定靜態(tài)庫(kù).a所依賴的.c文件及其路徑,若路徑中包含"http://"則表示絕對(duì)路徑(此處為代碼根路徑),若不包含"http://"則表示相對(duì)路徑。
- include_dirs中指定source所需要依賴的.h文件路徑。
添加新組件。
修改文件build/lite/components/communication.json,添加組件hello_world_app的配置,如下所示為communication.json文件片段,"##start##"和"##end##"之間為新增配置("##start##"和"##end##"僅用來(lái)標(biāo)識(shí)位置,添加完配置后刪除這兩行):
{
"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/wifi-iot/app/my_first_app"
],
"targets": [
"http://applications/sample/wifi-iot/app/my_first_app:myapp"
],
"rom": "",
"ram": "",
"output": [],
"adapted_kernel": [ "liteos_m" ],
"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"
],
`HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿`
- 修改單板配置文件。
修改文件vendor/hisilicon/hispark_pegasus/config.json,新增hello_world_app組件的條目,如下所示代碼片段為applications子系統(tǒng)配置,"##start##"和"##end##"之間為新增條目("##start##"和"##end##"僅用來(lái)標(biāo)識(shí)位置,添加完配置后刪除這兩行):{ "subsystem": "applications", "components": [ ##start## { "component": "hello_world_app", "features":[] }, ##end## { "component": "wifi_iot_sample_app", "features":[] } ] },
審核編輯 黃宇
-
源碼
+關(guān)注
關(guān)注
8文章
653瀏覽量
29518 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5137瀏覽量
98344 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2397瀏覽量
43098 -
Hi3861
+關(guān)注
關(guān)注
1文章
62瀏覽量
6621 -
OpenHarmony
+關(guān)注
關(guān)注
25文章
3753瀏覽量
16670
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
鴻蒙OpenHarmony【輕量系統(tǒng)運(yùn)行】 (基于Hi3861開發(fā)板)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>【<b class='flag-5'>輕</b><b class='flag-5'>量</b><b class='flag-5'>系統(tǒng)</b>運(yùn)行】 (基于<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>)](https://file1.elecfans.com/web2/M00/D6/1B/wKgaomYmY5SACwetAABPlIer1CU079.jpg)
鴻蒙OpenHarmony【集成三方SDK】 (基于Hi3861開發(fā)板)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>【集成三方SDK】 (基于<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>)](https://file1.elecfans.com/web2/M00/C5/CD/wKgZomYCdwyAIFf5AAB_7E1pFms943.jpg)
鴻蒙OpenHarmony【標(biāo)準(zhǔn)系統(tǒng)編寫“Hello World”程序】 (基于RK3568開發(fā)板)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>【標(biāo)準(zhǔn)<b class='flag-5'>系統(tǒng)編寫</b>“<b class='flag-5'>Hello</b> <b class='flag-5'>World</b>”<b class='flag-5'>程序</b>】 (基于RK3568<b class='flag-5'>開發(fā)板</b>)](https://file1.elecfans.com/web2/M00/C5/CD/wKgZomYCdwyAIFf5AAB_7E1pFms943.jpg)
鴻蒙OpenHarmony【輕量系統(tǒng) 環(huán)境搭建】 (基于Hi3861開發(fā)板)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>【<b class='flag-5'>輕</b><b class='flag-5'>量</b><b class='flag-5'>系統(tǒng)</b> 環(huán)境搭建】 (基于<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>)](https://file1.elecfans.com/web2/M00/DB/70/wKgZomYrdQKAVmNbAAD2f7eOBJs616.jpg)
鴻蒙OpenHarmony【輕量系統(tǒng) 運(yùn)行】 (基于Hi3861開發(fā)板)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>【<b class='flag-5'>輕</b><b class='flag-5'>量</b><b class='flag-5'>系統(tǒng)</b> 運(yùn)行】 (基于<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>)](https://file1.elecfans.com/web2/M00/DD/F8/wKgaomYsw9GAc-_nAACZ3W2Vym8965.jpg)
盤點(diǎn)那些硬件+項(xiàng)目學(xué)習(xí)套件:Hi3861鴻蒙開發(fā)板及入門常見問題解答
如何使用 HiBurn 工具燒錄鴻蒙的 .bin 文件到 Hi3861 開發(fā)板
關(guān)于OpenHarmony輕量系統(tǒng)開發(fā)
基于鴻蒙系統(tǒng)+Hi3861的WiFi小車開發(fā)
![基于<b class='flag-5'>鴻蒙</b><b class='flag-5'>系統(tǒng)</b>+<b class='flag-5'>Hi3861</b>的WiFi小車<b class='flag-5'>開發(fā)</b>](https://file.elecfans.com/web2/M00/33/A7/poYBAGIgHKeADywGAAKAsdAsO78520.png)
自制Hi3861開發(fā)板(附原理圖和電路圖)
![自制<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>(附原理圖和電路圖)](https://file.elecfans.com//web2/M00/3D/12/pYYBAGJXhZ6ADWc2AAxYv4KKQrI366.png)
潤(rùn)開鴻Hi3861開發(fā)板介紹
![潤(rùn)開鴻<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>介紹](https://file1.elecfans.com//web2/M00/82/55/wKgaomRJ5S2ATV_uAAug8w8E8MQ484.png)
鴻蒙OpenHarmony【輕量系統(tǒng)編寫“Hello World”程序】 (基于Hi3861開發(fā)板)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>【<b class='flag-5'>輕</b><b class='flag-5'>量</b><b class='flag-5'>系統(tǒng)編寫</b>“<b class='flag-5'>Hello</b> <b class='flag-5'>World</b>”<b class='flag-5'>程序</b>】 (基于<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>)](https://file1.elecfans.com/web2/M00/C5/D1/wKgZomYChGOAUaiiAADe1d8SeRY102.jpg)
鴻蒙OpenHarmony【輕量系統(tǒng)編譯】 (基于Hi3861開發(fā)板)
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>【<b class='flag-5'>輕</b><b class='flag-5'>量</b><b class='flag-5'>系統(tǒng)</b>編譯】 (基于<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>)](https://file1.elecfans.com/web2/M00/C5/D1/wKgZomYChGOAUaiiAADe1d8SeRY102.jpg)
鴻蒙OpenHarmony南向:【Hi3861開發(fā)板介紹】
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>OpenHarmony</b>南向:【<b class='flag-5'>Hi3861</b><b class='flag-5'>開發(fā)板</b>介紹】](https://file1.elecfans.com/web2/M00/E1/98/wKgaomY4nymAGhj6AAiNkRdS0qQ673.jpg)
評(píng)論