当前位置: 首页 > news >正文

RK3568 OH5.1 编译运行程序hellworld

编写helloworld

  1. 代码根目录创建sample子系统文件夹
  2. 在子系统目录下创建hello部件文件夹
  3. hello文件夹中创建hello源码目录及源码

sample/hello/src/helloworld.c:

#include <stdio.h>
#include "helloworld.h"void hello_oh(void);int main(int argc, char *argv[])
{hello_oh();HelloWorld();return 0;
}
void HelloWorld(void)
{printf("\n\n");printf("Hello World!\n");printf("\n\n");
}void hello_oh(void)
{printf("\n\n");printf("Hello OpenHarmony!\n");printf("\n\n");
}

sample/hello/include/helloworld.h:

#ifndef __HELLOWORLD_H__
#define __HELLOWORLD_H__#ifdef __cplusplus
extern "C" {
#endifvoid HelloWorld();#ifdef __cplusplus
}
#endif#endif
  1. 构建文件BUILD.gn及部件配置文件bundle.json。

sample/hello/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  # 是否默认安装(缺省默认不安装),可选
}

sample/hello/bundle.json:

{"name": "@ohos/hello","description": "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": []}}
}
  1. 修改子系统配置文件

build/subsystem_config.json:

"sample": {"path": "sample","name": "sample"},

添加自定义的sample子系统

  1. 修改产品配置文件

vendor/hihope/rk3568/config.json:

{"subsystem": "sample","components": [{"component": "hello","features": []}]
},     

在产品选中加入自定义的子系统。

最后整个sample子系统目录结构如下:

sample/
└── hello├── BUILD.gn├── bundle.json├── include│   └── helloworld.h└── src└── helloworld.c

编译

指定编译helloworld模块:

./build.sh --product-name rk3568 --ccache --build-target helloworld

编译完成后目标文件所在位置:out/rk3568/sample/hello/helloworld

编译好的程序默认安装在system分区中:

system/system/bin/helloworld

每编译一次镜像太久了,就算是单独编译镜像也要很久:

./build.sh --product-name rk3568 --ccache --build-target system_image

为了快速验证,直接将编译的helloworld拷贝进镜像里:

mkdir system
sudo mount system.img system
sudo cp ../../../sample/hello/helloworld system/system/bin/
sudo umount system

hdc shell连接调试终端,执行helloworld:

相关文章:

  • 用美图秀秀批处理工具定制专属图片水印的方法详解
  • Android Native 之 adbd进程分析
  • matlab计算转子系统的固有频率、振型、不平衡响应
  • Java进化之路:从Java 8到Java 21的重要新特性(深度解析)
  • 爬虫--以爬取小说为例
  • 【google 论文】Titans: Learning to Memorize at Test Time
  • grounded_sam2 使用踩坑笔记
  • 第100+41步 ChatGPT学习:R语言实现误判病例分析
  • 【Oracle】DML语言
  • 没有公网ip如何实现外网访问?本地内网服务器应用端口让公网连接使用方法
  • 基于RK3568/RK3588/全志H3/飞腾芯片/音视频通话程序/语音对讲/视频对讲/实时性好/极低延迟
  • 使用el-input数字校验,输入汉字之后校验取消不掉
  • PCB设计实践(三十)地平面完整性
  • Flume 自定义拦截器开发实战:添加时间戳与 JSON 处理
  • Vue 3.0 中的路由导航守卫详解
  • 头歌之动手学人工智能-Pytorch 之线性回归
  • python打卡训练营打卡记录day40
  • 电网即插即用介绍
  • mysql数据库基础命令总结常用10个
  • 2025年全国青少年信息素养大赛 scratch图形化编程挑战赛 小高组初赛 内部模拟试卷解析
  • 网站数据库查询怎么做/泉州百度竞价推广
  • 接工程平台/商丘seo教程
  • 什么网站百度收录快/广州网站营销seo费用
  • wordpress数据库名/短视频seo排名
  • 一键优化下载安装/谷歌seo营销
  • 深圳网站设计网站制作/谁有恶意点击软件