# 应用开发 ***Copyright © Quectel Wireless Solutions Co., Ltd. 2026. All rights reserved.*** --- 本文档介绍如何在Quectel Pi H1的Debian系统上进行应用开发。应用开发是指在开发板上编写、编译和运行应用程序的过程。Quectel Pi H1支持两种开发方式: - **本地开发**:直接在开发板上进行开发、编译和运行,适合快速开发和调试 - **交叉编译**:在PC主机上编译代码,生成可在开发板上运行的可执行文件,适合资源受限或需要更高编译效率的场景 本文档将以经典的HelloWorld程序为例,详细介绍这两种开发方式的完整流程,帮助开发者快速上手Quectel Pi H1的应用开发。 # HelloWorld示例 HelloWorld是一个简单的C语言程序,主要用于验证开发环境搭建是否成功。通过编写、编译和运行这个基础程序,可以测试系统的基本功能,包括编译器、运行时环境等是否正常工作,是嵌入式开发入门的基础实践。 ## 本地开发 本地开发是指在Quectel Pi H1开发板上直接进行开发、编译和运行。这种方式操作简单,适合快速验证和调试。 ### 搭建开发环境 登录到Quectel Pi H1的Debian系统后,打开终端窗口,输入以下命令并回车,安装必要的开发环境: ```bash sudo apt update && sudo apt install vim gawk gcc g++ build-essential chrpath socat wget diffstat file unzip tar locales zstd debianutils iputils-ping cpio python3 python3-pip net-tools git make cmake ``` ### 编写代码 1. 在 **/Desktop** 目录下创建 **helloworld.c** 文件。 2. 复制以下代码段,粘贴在 **helloworld.c** 文件内: ```c #include int main(void){printf("hello world\r\n");return 0;} ``` ### 编译与运行 3. 执行以下命令,编译代码: ```shell $ cd Desktop/ $ gcc helloworld.c -o helloworld ``` 4. 执行以下命令,运行helloworld程序: ```shell $ ./helloworld ``` 5. 程序运行结果打印: ```shell $ ./helloworld $ hello world ``` ## 交叉编译 交叉编译是在一种平台(如x86 PC)上,生成可以在另一种不同体系结构的平台(如ARM嵌入式设备)上运行的可执行程序。这种方式可以在性能更强的PC上进行编译,提高开发效率。 ### 准备工作 - 一台32/64位主机计算机,用于编译代码。 - 一块Quectel Pi H1开发板,用于运行可执行程序。 以64位计算机为例,在主机上执行如下步骤: ### 安装ARM64工具链 ```bash sudo apt update sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu ``` ### 验证安装 ```bash $ aarch64-linux-gnu-gcc --version ``` ```{image} images/image_YGitbY940orCguxt4ZScNtZynEh.webp :width: 624px :height: 100px ``` ### 创建代码文件 ```bash $ touch hello.c $ sudo vim hello.c ``` 按下 **ESC + i**,输入下面代码,然后再按 **ESC + "shift + : "**,在命令台输入 "**wq+Enter**" 保存退出。 ```c #include int main() {printf("Hello World!\n");return 0;} ``` ```{image} images/image_CYvZbKtAYoAeQZxCQC9cA9T4n9z.webp :width: 596px :height: 325px ``` ### 编译代码文件 ```bash $ aarch64-linux-gnu-gcc -o 生成编译文件名 原文件名 例:aarch64-linux-gnu-gcc -o hello_arm64 hello.c ``` ### 检查文件架构 ```bash $ file 文件名 ``` 编译成功如下所示: ```{image} images/image_Z5yEbDuzfovBWXxTwrscYcnFnxb.webp :width: 1071px :height: 60px ``` ### 上传编译文件 将主机上的编译文件下载到本地,然后在Windows控制台通过SCP命令上传编译文件至Quectel Pi H1开发板。 ```bash #注:主机编译文件的存放路径不要使用中文scp -O /本地/文件.txt username@远程IP:/目标路径/ 例:scp -O D:\hello_arm64 pi@192.168.x.x:/home/pi ``` ```{image} images/image_QGQ8b5NSWoEU82xR1LAclTpgnKg.webp :width: 973px :height: 151px ``` ### 运行编译文件 在Quectel Pi H1开发板终端上为编译文件设置权限并执行。 ```bash sudo chmod 777 文件名 ``` ```{image} images/image_LxkTb4KNroFKp2xzCx4cVYMynhf.webp :width: 342px :height: 49px ```