当前位置: 首页 > 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:

http://www.xdnf.cn/news/732907.html

相关文章:

  • (22)大文件流式处理
  • 五星级酒店技能比赛主持稿串词
  • framework之慕课大巴
  • PCL 渲染显示
  • 电子电路:初步认识4013D触发器
  • 【深度剖析】义齿定制行业数字化转型模式创新研究(上篇3:数字化转型动机分析)
  • 实验设计与分析(第6版,Montgomery)第5章析因设计引导5.7节思考题5.13 R语言解题
  • 人工智能编程学习心得:从零基础到独立开发的蜕变之路
  • 副本(Replica)在Elasticsearch中扮演什么角色?
  • 算力租赁革命:弹性模式如何重构数字时代的创新门槛​
  • MATLAB项目实战:阻尼振动与数据拟合项目
  • 大模型长对话中上下文无法承载全部历史,如何压缩或提取重点
  • 2025Mybatis最新教程(二)
  • 什么是知识蒸馏?如何做模型蒸馏?结合案例说明
  • 电子电路:深入了解4013D触发器的机制和原理
  • 加强LLM防御以实现企业部署
  • spring切面
  • 栈与队列:数据结构的有序律动
  • JS入门——三种输入方式
  • docker不用dockerfile
  • GSR 手环能耗数据实测:STM32 与 SD NAND 的功耗优化成果
  • 信息安全管理与评估2025山东卷
  • ONLYOFFICE深度解锁系列.4-OnlyOffice客户端原理-真的不支持多端同步
  • 使用 Kafka + Protobuf 实现高效的序列化通信
  • 【合集】Linux——31个普通信号
  • Eclipse集成lombok
  • 电子电路:VCC电源是什么?
  • 从图像处理到深度学习:直播美颜SDK的人脸美型算法详解
  • 初学c语言21(文件操作)
  • 小程序32-简易双向数据绑定