1.写代码时xxx.c为业务代码,xxx.gn为编译脚本 2.头文件ohos_init.h 提供用于在服务开发期间初始化服务和功能的条目(不必深入理解)
3.
截图代码中最后一句,必须有APP_FEATURE_INIT(Hello_World)才能让自己写的代码运行,其中INIT定义在头文件#include "ohos_init.h"中,如果没有头文件的话,这行代码没有作用。
4.static_library中指定业务模块的编译结果,为静态库文件libmyapp.a,开发者根据实际情况完成填写。 作用是将sources中"hello_world.c"编写成libmyapp.a文件。 sources中指定静态库.a所依赖的.c文件及其路径,若路径中包含"//“则表示绝对路径,若不包含”//" 则表示相对路径。作用是指定编写文件的名称和路径。 include_dirs是指定source中"hello_world.c"所需要依赖的.h文件路径。 
5.写在features中的"my_app:myapp",作用是编译myapp文件 my_app是相对路径,指向./applications/BearPi/BearPi-HM/sample/my_app/BUILD.gn。 myapp是目标,指向./applications/BearPi/BearPi-HM/sample/my_app/BUILD.gn中的static_library(“myapp”) 
6.GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_2,1);//设置GPIO_2输出高电平点亮LED灯 1为High,2为Low
搭建环境注意事项:
1.RaiDrive添加新虚拟驱动时不要选择只读,否则在VS Code编译源代码时无法新建文件 
2.MobaXtern和RaiDrive可能会出现连接超时连接不上的情况,重新运行软件,或者重启电脑就能解决。
3.安装CH341SER驱动时,可能由于电脑之前下载过usb转ttl模块,需要先点击卸载然后再点击安装

案例运行
 
|