1# Writing a Hello World Program
2
3
4The following exemplifies how to run the first program on the development board. This program displays the message "Hello World!".
5
6
7## Prerequisites
8
9A project for the RK3568 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
14Obtain the OpenHarmony project code. From the source code root directory, add the **sample/hello** directory, and then create therein the **hello** source code directory, the build file **BUILD.gn**, and the component configuration file **bundle.json**.
15The complete code directory is as follows:
16
17
18```
19sample/hello
20│── BUILD.gn
21│── include
22│   └── helloworld.h
23│── src
24│   └── helloworld.c
25├── bundle.json
26build
27└── subsystem_config.json
28vendor/hihope
29└── rk3568
30    └── config.json
31```
32
33
34## How to Develop
35
36Perform the steps below in the source code directory:
37
381. Create a directory and write the service code.
39
40   Create the **sample/hello/src/helloworld.c** file, with the sample code as follows. In this example, the content to be printed is **World**, which you can change to any string that you prefer, for example, **OHOS**. Declare the string printing function **HelloPrint** in the **helloworld.h** file. You can use either C or C++ to develop a program.
41
42
43   ```
44   #include <stdio.h>
45   #include "helloworld.h"
46
47   int main(int argc, char **argv)
48   {
49       HelloPrint();
50       return 0;
51   }
52
53   void HelloPrint()
54   {
55       printf("\n\n");
56       printf("\n\t\tHello World!\n");
57       printf("\n\n");
58   }
59   ```
60
61   Add the header file **sample/hello/include/helloworld.h**. The sample code is as follows:
62
63
64   ```
65   #ifndef HELLOWORLD_H
66   #define HELLOWORLD_H
67   #ifdef __cplusplus
68   #if __cplusplus
69   extern "C" {
70   #endif
71   #endif
72
73   void HelloPrint();
74
75   #ifdef __cplusplus
76   #if __cplusplus
77   }
78   #endif
79   #endif
80   #endif // HELLOWORLD_H
81   ```
82
832. Create a build file.
84
85   Create the **sample/hello/BUILD.gn** file. For details, see [Module](../subsystems/subsys-build-module.md).
86
87   The content of the **BUILD.gn** file is as follows:
88
89   ```
90   import("//build/ohos.gni") # Import the build template.
91   ohos_executable("helloworld") {# Executable module.
92     sources = [       # Source code of the module.
93       "src/helloworld.c"
94     ]
95     include_dirs = [  # Directory of header files on which the module depends.
96       "include"
97     ]
98     cflags = []
99     cflags_c = []
100     cflags_cc = []
101     ldflags = []
102     configs = []
103     deps =[]    # Internal dependencies of a component.
104     part_name = "hello"    # Component name. This parameter is mandatory.
105     install_enable = true # Whether to install the software by default. This parameter is optional. By default, the software is not installed.
106   }
107   ```
108
1093. Create a component configuration file.
110
111   Create the **sample/hello/bundle.json** file and add the **sample** component description therein. For details, see [Component](../subsystems/subsys-build-component.md).
112
113   The content of the **bundle.json** file is as follows:
114
115   ```
116   {
117       "name": "@ohos/hello",
118       "description": "Hello world example.",
119       "version": "3.1",
120       "license": "Apache License 2.0",
121       "publishAs": "code-segment",
122       "segment": {
123           "destPath": "sample/hello"
124       },
125       "dirs": {},
126       "scripts": {},
127       "component": {
128           "name": "hello",
129           "subsystem": "sample",
130           "syscap": [],
131           "features": [],
132           "adapted_system_type": [ "mini", "small", "standard" ],
133           "rom": "10KB",
134           "ram": "10KB",
135           "deps": {
136               "components": [],
137               "third_party": []
138           },
139           "build": {
140               "sub_component": [
141                   "//sample/hello:helloworld"
142               ],
143               "inner_kits": [],
144               "test": []
145           }
146       }
147   }
148   ```
149
150   The **bundle.json** file consists of two parts. The first part describes the information about the subsystem to which the component belongs, and the second part defines the build configuration for the component. When adding a component, you must specify the **sub_component** of the component. If there are APIs provided for other components, add them in **inner_kits**. If there are test cases, add them in **test**.
151
1524. Modify the subsystem configuration file.
153
154   Add the configuration of the new subsystem to the **build/subsystem_config.json** file. For details, see [Subsystem](../subsystems/subsys-build-subsystem.md).
155
156   The configuration of the new subsystem is as follows:
157
158   ```
159   "sample": {
160       "path": "sample",
161       "name": "sample"
162     },
163   ```
164
1655. Modify the product configuration file.
166
167      > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
168      >
169      > In versions earlier than OpenHarmony-v3.2-Beta2, the RK3568 configuration file is **productdefine/common/products/rk3568.json**. In OpenHarmony-v3.2-Beta2 and later versions, the RK3568 configuration file is **vendor/hihope/rk3568/config.json**.
170
171   - Versions earlier than OpenHarmony-v3.2-Beta2
172
173      In the **productdefine/common/products/rk3568.json** file, add the **hello** part after the existing part.
174
175       ```
176       "usb:usb_manager_native":{},
177       "applications:prebuilt_hap":{},
178       "sample:hello":{},
179       "wpa_supplicant-2.9:wpa_supplicant-2.9":{},
180       ```
181
182   - OpenHarmony-v3.2-Beta2 and later versions
183
184     In the **vendor/hihope/rk3568/config.json** file, add the **hello** part after the existing part.
185
186       ```
187       {
188         "subsystem": "sample",
189         "components": [
190           {
191             "component": "hello",
192             "features": []
193           }
194         ]
195       },
196       ```
197