Ubuntu系列-Build first snap app--hello snap

本文详细介绍如何在Ubuntu 16.04及以上系统中使用Snapcraft工具创建一个简单的Snap应用程序。通过配置snapcraft.yaml文件并编译C语言源代码,最终打包成Snap格式的应用程序,并安装及运行。

参考网页:
ubuntu snap

编译环境:
ubuntu 16.04以上系统

主要思想:
配置snapcraft.yaml文件,配置中之处编译的工具,和编译源码的所在。下面是一个简单的snap app。

mkdir hello-wmy/
cd hello-wmy/
touch snapcraft.yaml
vim snapcraft.yaml:

name: hello-wmy
version: "0.1"
summary: orbbec first snap app
description: puts up a square
confinement: strict

build-packages:
  - gcc

apps:
  hello-wmy:
    # FIXME: remove opengl-launch once base wrappers set LIBGL_DRIVERS_PATH
    command: hello-wmy
    # Many apps do this instead, but it requires e.g. 'after: [desktop-gtk2]', which makes the snap huge
    #command: desktop-launch $SNAP/bin/hellogl

parts:
  hello-wmy:
    source: .
    plugin: cmake

vim CMakeLists.txt

PROJECT (HELLO)
SET(SRC_LIST hello-wmy.c)
ADD_EXECUTABLE(hello-wmy ${SRC_LIST})

install(TARGETS hello-wmy DESTINATION bin)

vim hell-wmy.c

#include <stdio.h>

void main()
{
  printf("hello snaps.\n");

}

最好事先安装CMake:apt-get install cmake

最后执行:sudo snapcraft

生成hello-wmy_0.1_amd64.snap 应用。

然后安装这个snap app到本地:
sudo snap install hello-wmy_0.1_amd64.snap –dangerous
然后运行:hello-wmy 会出现打印:hello snaps。说明成功!

需要加入 –dangerous 配置,因为现在这个snap没有经过签名。

如果提示没有找到–dangerous这个配置,更新一下snapd这个工具包:
apt-get install snapd

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值