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