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