• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Writing a Hello World Program
2
3
4The following exemplifies how to run the first program on the development board. The created program outputs the message "Hello World!"
5
6
7## Prerequisites
8
9A project for the Hi3516 development board has been created as instructed in [Creating a Project and Obtaining Source Code](quickstart-ide-import-project.md).
10
11
12## Example Directory
13
14The complete code directory is as follows:
15
16
17
18```
19applications/sample/hello
20│── BUILD.gn
21└── src
22    └── helloworld.c
23```
24
25
26## How to Develop
27
28Perform the steps below in the source code directory:
29
301. Create a directory and the program source code.
31
32   Create the **applications/sample/hello/src/helloworld.c** directory and file whose code is shown in the following example. You can customize the content to be printed. For example, you can change **OHOS** to **World**. You can use either C or C++ to develop a program.
33
34
35   ```
36   #include <stdio.h>
37
38   int main(int argc, char **argv)
39   {
40       printf("\n\n");
41       printf("\n\t\tHello OHOS!\n");
42       printf("\n\n\n");
43
44       return 0;
45   }
46   ```
47
482. Create a build file.
49
50   Create the **applications/sample/hello/BUILD.gn** file. The file content is as follows:
51
52
53   ```
54   import("//build/lite/config/component/lite_component.gni")
55   lite_component("hello-OHOS") {
56     features = [ ":helloworld" ]
57   }
58   executable("helloworld") {
59     output_name = "helloworld"
60     sources = [ "src/helloworld.c" ]
61   }
62   ```
63
643. Add a component.
65
66   Modify the **build/lite/components/applications.json** file and add the configuration of **hello_world_app**. The following code snippet is a snippet of the **applications.json** file, where the configuration between **\#\#start\#\#** and **\#\#end\#\#** is the new entry. (The **\#\#start\#\#** and **\#\#end\#\#** lines are only used to identify the location. After the configuration is complete, delete these lines.)
67
68   > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
69   >
70   > In this example, the OpenHarmony-v3.1-Release version is used, where the component configuration file is **build/lite/components/applications.json**. In OpenHarmony-v3.2-Beta2 and later versions, the component configuration file is **build/lite/components/communication.json**.
71
72
73   ```
74   {
75     "components": [
76       {
77         "component": "camera_sample_communication",
78         "description": "Communication related samples.",
79         "optional": "true",
80         "dirs": [
81           "applications/sample/camera/communication"
82         ],
83         "targets": [
84           "//applications/sample/camera/communication:sample"
85         ],
86         "rom": "",
87         "ram": "",
88         "output": [],
89         "adapted_kernel": [ "liteos_a" ],
90         "features": [],
91         "deps": {
92           "components": [],
93           "third_party": []
94         }
95       },
96   ##start##
97       {
98         "component": "hello_world_app",
99         "description": "hello world samples.",
100         "optional": "true",
101         "dirs": [
102           "applications/sample/hello"
103         ],
104         "targets": [
105           "//applications/sample/hello:hello-OHOS"
106         ],
107         "rom": "",
108         "ram": "",
109         "output": [],
110         "adapted_kernel": [ "liteos_a" ],
111         "features": [],
112         "deps": {
113           "components": [],
114           "third_party": []
115         }
116       },
117   ##end##
118       {
119         "component": "camera_sample_app",
120         "description": "Camera related samples.",
121         "optional": "true",
122         "dirs": [
123           "applications/sample/camera/launcher",
124           "applications/sample/camera/cameraApp",
125           "applications/sample/camera/setting",
126           "applications/sample/camera/gallery",
127           "applications/sample/camera/media"
128         ],
129   ```
130
1314. Modify the board configuration file.
132
133   Modify the **vendor/hisilicon/hispark_taurus/config.json** file and add an entry for the **hello_world_app** component. The following code snippet is the configuration of the **applications** subsystem, where the configuration between **\#\#start\#\#** and **\#\#end\#\#** is the new entry. (The **\#\#start\#\#** and **\#\#end\#\#** lines are only used to identify the location. After the configuration is complete, delete these lines.)
134
135
136   ```
137         {
138           "subsystem": "applications",
139           "components": [
140             { "component": "camera_sample_app", "features":[] },
141             { "component": "camera_sample_ai", "features":[] },
142   ##start##
143             { "component": "hello_world_app", "features":[] },
144   ##end##
145             { "component": "camera_screensaver_app", "features":[] }
146           ]
147         },
148   ```
149