上一篇报告中编译的系统实际是3.2版本的,从搭建开发环境,到拉代码和编译系统,都很顺利,新的版本以4.0和5.0为主了,所以后边的应用开发也准备基于4.0或者5.0版本的系统,没想到的是,编译4.0(5.0)系统遇到了各种各样的问题,比如下面这些:
后来使用了厂家搭建好的虚拟机环境,竟然也遇到了各种报错,如下面这些:
在快要编译完成的时候,竟然报虚拟机空间不够了,厂家的虚拟机环境200G的磁盘容量不够用了,只能再扩磁盘。扩盘前先要把多个虚拟机磁盘合并成一个磁盘后才能扩盘,第一次在编译5.0.1系统报错磁盘空间不够的时候做的扩盘,结果还没有成功,扩盘后系统不能启动。再新建了一个厂家的虚拟机环境,然后把源码库删除,先做扩盘到300G,再重新拉代码,编译系统,经过一番折腾之后,终于成功编译了出了5.0.1版本的系统。
镜像文件如下:
将新编译的镜像文件烧写到开发板,启动后的版本信息如下。
接下来就是准备第一个应用例程helloworld的开发。
在代码根目录创建sample子系统文件夹,在子系统目录下创建hello部件文件夹,hello文件夹中创建hello源码目录,构建文件BUILD.gn及部件配置文件bundle.json。 示例完整目录如下。
sample/hello
│── BUILD.gn
│── include
│ └── helloworld.h
│── src
│ └── helloworld.c
└── bundle.json
helloworld.c文件内容如下。
#include
#include "helloworld.h"
int main(int argc, char **argv)
{
HelloPrint();
return 0;
}
void HelloPrint()
{
printf("\n\n");
printf("\n\t\tHello World!\n");
printf("\n\n");
}
helloworld.h文件内容如下。
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
void HelloPrint();
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif // HELLOWORLD_H
编译组织文件BUILD.gn内容如下。
import("//build/ohos.gni") # 导入编译模板
ohos_executable("helloworld") { # 可执行模块
sources = [ # 模块源码
"src/helloworld.c"
]
include_dirs = [ # 模块依赖头文件目录
"include"
]
cflags = []
cflags_c = []
cflags_cc = []
ldflags = []
configs = []
deps =[] # 部件内部依赖
part_name = "hello" # 所属部件名称,必选
install_enable = true # 是否默认安装(缺省默认不安装),可选
}
部件配置规则文件bundle.json内容如下。
{
"name": "@ohos/hello",
"descrip tion": "Hello world example.",
"version": "3.1",
"license": "Apache License 2.0",
"publishAs": "code-segment",
"segment": {
"destPath": "sample/hello"
},
"dirs": {},
"scripts": {},
"component": {
"name": "hello",
"subsystem": "sample",
"syscap": [],
"features": [],
"adapted_system_type": [ "mini", "small", "standard" ],
"rom": "10KB",
"ram": "10KB",
"deps": {
"components": [],
"third_party": []
},
"build": {
"sub_component": [
"//sample/hello:helloworld"
],
"inner_kits": [],
"test": []
}
}
}
在build/subsystem_config.json中添加新建的子系统的配置。
"sample": {
"path": "sample",
"name": "sample"
},
在vendor/hihope/rk3568/config.json中添加对应的hello部件。
{
"subsystem": "sample",
"components": [
{
"component": "hello",
"features": []
}
]
},
再一次使用命令./build.sh --product-name rk3568 –ccache编译,在等待若干小时后,系统顺利编译完成。
镜像文件如下。
将镜像烧写到开发板后,连接好开发板的debug串口,打开串口终端,输入 命令helloworld,程序正确执行,如下所示。
至此,5.0.1版本的系统以及例程编译、执行完毕,接下来将编写第一个外设也就是串口的通讯例程。
|