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