quickstart-ide-lite-steps-hi3516-helloworld.md 3.8 KB
Newer Older
D
duangavin123 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# 编写“Hello World”程序


下方将展示如何在单板上运行第一个应用程序,其中包括新建应用程序、编译、烧写、运行等步骤,最终输出“Hello World!”。


## 示例目录

示例完整目录如下:


  
```
applications/sample/hello
│── BUILD.gn
D
duangavin123 已提交
16 17
└── src
    └── helloworld.c
D
duangavin123 已提交
18 19 20 21 22 23 24
```


## 开发步骤

请在源码目录中通过以下步骤创建“Hello World”应用程序:

D
duangavin123 已提交
25
1. 新建目录及源码。
L
liyan 已提交
26

D
duangavin123 已提交
27
   新建**applications/sample/hello/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。
D
duangavin123 已提交
28 29 30 31 32 33 34 35

     
   ```
   #include <stdio.h>
   
   int main(int argc, char **argv)
   {
       printf("\n\n");
D
duangavin123 已提交
36 37 38 39
       printf("\n\t\tHello OHOS!\n");
       printf("\n\n\n");
   
       return 0;
D
duangavin123 已提交
40 41 42
   }
   ```

D
duangavin123 已提交
43
2. 新建编译组织文件。
L
liyan 已提交
44

D
duangavin123 已提交
45
   新建**applications/sample/hello/BUILD.gn**文件,内容如下所示:
D
duangavin123 已提交
46 47 48

     
   ```
D
duangavin123 已提交
49 50 51 52 53 54 55
   import("//build/lite/config/component/lite_component.gni")
   lite_component("hello-OHOS") {
     features = [ ":helloworld" ]
   }
   executable("helloworld") {
     output_name = "helloworld"
     sources = [ "src/helloworld.c" ]
D
duangavin123 已提交
56 57 58
   }
   ```

D
duangavin123 已提交
59
3. 添加新组件。
L
liyan 已提交
60

Z
zwx1138075 已提交
61
   修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
D
duangavin123 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

     
   ```
   {
     "components": [
       {
         "component": "camera_sample_communication",
         "description": "Communication related samples.",
         "optional": "true",
         "dirs": [
           "applications/sample/camera/communication"
         ],
         "targets": [
           "//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": [
           "//applications/sample/hello:hello-OHOS"
         ],
         "rom": "",
         "ram": "",
         "output": [],
         "adapted_kernel": [ "liteos_a" ],
         "features": [],
         "deps": {
           "components": [],
           "third_party": []
         }
       },
   ##end##
D
duangavin123 已提交
109
       {
D
duangavin123 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122
         "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"
         ],
   ```

4. 修改单板配置文件。
L
liyan 已提交
123

D
duangavin123 已提交
124
   修改文件**vendor/hisilicon/hispark_taurus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
D
duangavin123 已提交
125 126 127

     
   ```
D
duangavin123 已提交
128 129 130 131 132 133 134 135 136 137 138
         {
           "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":[] }
           ]
         },
D
duangavin123 已提交
139
   ```