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## Example Directory 8 9The complete code directory is as follows: 10 11 12 13``` 14applications/sample/hello 15│── BUILD.gn 16└── src 17 └── helloworld.c 18``` 19 20 21## How to Develop 22 23Perform the steps below in the source code directory: 24 251. Create a directory and the program source code. 26 27 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. 28 29 30 ``` 31 #include <stdio.h> 32 33 int main(int argc, char **argv) 34 { 35 printf("\n\n"); 36 printf("\n\t\tHello OHOS!\n"); 37 printf("\n\n\n"); 38 39 return 0; 40 } 41 ``` 42 432. Create a build file. 44 45 Create the **applications/sample/hello/BUILD.gn** file. The file content is as follows: 46 47 48 ``` 49 import("//build/lite/config/component/lite_component.gni") 50 lite_component("hello-OHOS") { 51 features = [ ":helloworld" ] 52 } 53 executable("helloworld") { 54 output_name = "helloworld" 55 sources = [ "src/helloworld.c" ] 56 } 57 ``` 58 593. Add a component. 60 61 Modify the **build/lite/components/communication.json** file and add the configuration of **hello_world_app**. The following code snippet is a snippet of the **communication.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.) 62 63 64 ``` 65 { 66 "components": [ 67 { 68 "component": "camera_sample_communication", 69 "description": "Communication related samples.", 70 "optional": "true", 71 "dirs": [ 72 "applications/sample/camera/communication" 73 ], 74 "targets": [ 75 "//applications/sample/camera/communication:sample" 76 ], 77 "rom": "", 78 "ram": "", 79 "output": [], 80 "adapted_kernel": [ "liteos_a" ], 81 "features": [], 82 "deps": { 83 "components": [], 84 "third_party": [] 85 } 86 }, 87 ##start## 88 { 89 "component": "hello_world_app", 90 "description": "hello world samples.", 91 "optional": "true", 92 "dirs": [ 93 "applications/sample/hello" 94 ], 95 "targets": [ 96 "//applications/sample/hello:hello-OHOS" 97 ], 98 "rom": "", 99 "ram": "", 100 "output": [], 101 "adapted_kernel": [ "liteos_a" ], 102 "features": [], 103 "deps": { 104 "components": [], 105 "third_party": [] 106 } 107 }, 108 ##end## 109 { 110 "component": "camera_sample_app", 111 "description": "Camera related samples.", 112 "optional": "true", 113 "dirs": [ 114 "applications/sample/camera/launcher", 115 "applications/sample/camera/cameraApp", 116 "applications/sample/camera/setting", 117 "applications/sample/camera/gallery", 118 "applications/sample/camera/media" 119 ], 120 ``` 121 1224. Modify the board configuration file. 123 124 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.) 125 126 127 ``` 128 { 129 "subsystem": "applications", 130 "components": [ 131 { "component": "camera_sample_app", "features":[] }, 132 { "component": "camera_sample_ai", "features":[] }, 133 ##start## 134 { "component": "hello_world_app", "features":[] }, 135 ##end## 136 { "component": "camera_screensaver_app", "features":[] } 137 ] 138 }, 139 ``` 140