Ubuntu安装和使用ubus

1、引言

ubus是OpenWrt中的进程间通信机制。Ubus源码可以很容易地从网上下载到,但是要想应用到实际项目中,需要进行移植。

2、依赖关系

Ubus是新的openWrt中引入的一个消息总线,主要作用是实现不同应用程序之间的信息交互。Ubus的编译和运行依赖libubox中的一些内容,而libubox又依赖于json-c中的内容,环环相扣。因此,我们需要按照先json-c,后libubox,最后ubus的顺序来编译。

如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

3、参考文章

1、移植编译libubox、ubus、json-c的详细过程
2、ubus 编译安装到Ubuntu 16.04
3、Linux json-c 安装和使用

4、下载源码(创建一个目录保存源码)

git clone https://github.com/json-c/json-c.git
git clone http://git.openwrt.org/project/libubox.git
git clone https://git.openwrt.org/project/ubus.git

5、编译安装json-c

cd json-c
mkdir build
cd build
cmake …/
可以 ls 查看是否有 Makefile
make
sudo make install
cd /usr/local/include
sudo mv json-c json

6、编译安装libubox

cd libubox/
mkdir build
vi CMakeLists.txt

修改 OPTION(BUILD_LUA “build Luaplugin” ON) -----> ON 改为 OFF。在当前行上面添加下面数据

include_directories("/usr/local/include")
link_directories("/usr/local/lib")

修改文件/libubox/examples/json_script-example.c

#include <stdio.h>
#include <stdlib.h>

#include <json/json.h> #修改这行
#include "blobmsg.h"
#include "blobmsg_json.h"
#include "json_script.h"

struct json_script_ctx	jctx;
struct blob_buf 	b_vars;
struct blob_buf 	b_script;

static void handle_command(struct json_script_ctx *ctx, const char *name,
	struct blob_attr *data, struct blob_attr *vars)
{
	struct blob_attr *cur;
	size_t rem;

	fprintf(stdout, "%s", name);
	blobmsg_for_each_attr(cur, data, rem)
		fprintf(stdout, " %s", (char *) blobmsg_data(cur));
	fprintf(stdout, "\n");
}

接着执行下面命令

cd build
cmake …/
make
sudo make install

7、编译安装ubus

cd ubus
mkdir build
vi CMakeLists.txt

修改 OPTION(BUILD_LUA “build Luaplugin” ON) -----> ON 改为 OFF。在当前行上面添加下面数据

include_directories("/usr/local/include")
link_directories("/usr/local/lib")

cd build
cmake …/
make
sudo make install

8、代码编写—》后面有空再写

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值