mipsel-openwrt-linux交叉编译zlog日志库并测试
文章目录
一、准备
GitHub:https://github.com/HardySimpson/zlog
https://github.com/bmanojlovic/zlog
正常linux下编译安装测试指导:
http://hardysimpson.github.io/zlog/
交叉编译指导:
https://blog.youkuaiyun.com/lc250123/article/details/54174401
正常的编译安装这里就不多说了,没有什么问题,ubuntu16.04下本人测试可以使用,下面主要总结交叉编译使用。
根据
https://www.oschina.net/question/576144_58926?sort=defaultundefinedp=1
所说,其单进程下使用内存占用在2-3M,我的板子够用,其他人移植请注意RAM资源是否够用。
二、交叉编译测试
1.mipsel-openwrt-linux交叉编译过程(arm类似)
#下载可交叉编译的版本:
git clone https://github.com/bmanojlovic/zlog
cd zlog
mkdir mipsel
#修改configure脚本的生成脚本可执行权限
chmod +x autogen.sh
如果出现不能识别的函数错误,或报"Syntax error: "(" unexpected 的错误,请取消dash:
dpkg-reconfigure dash
选择 no;
然后再执行:./autogen.sh
#配置configure脚本
CC=mipsel-openwrt-linux-gcc-4.8.3 ./configure --prefix=/home/ubuntu/work/zlog/mipsel --host=mipsel-openwrt-linux
#开始编译
执行:make
可能会出现以下错误:
./.libs/libzlog.so: undefined reference to `rpl_realloc'
这时,我们要改 makefile 文件,cd 到 src 文件下,修改 Makefile:将 rpl_realloc 替换为 realloc,保存
#再次编译
make clean
make
#安装
make install
编译安装成功后,会在之前指定的安装目录下安装好:
ubuntu@ubuntu-virtual-machine:~/work/zlog/mipsel$ tree
.
├── bin
│ └── zlog-chk-conf
├── cross_mipsel_openwrt
│ ├── compile.sh
│ ├── test.c
│ ├── test_zlog
│ └── test_zlog.conf
├── include
│ └── zlog.h
├── lib
│ ├── libzlog.a
│ ├── libzlog.la
│ ├── libzlog.so -> libzlog.so.1.1.0
│ ├── libzlog.so.1 -> libzlog.so.1.1.0
│ └── libzlog.so.1.1.0
└── share
└── man
└── man1
└── zlog-chk-conf.1
7 directories, 12 files
然后我直接在该目录下创建编译目录cross_mipsel_openwrt,在其下创建交叉编译脚本和测试程序以及zlog配置文件。
2.测试代码
#include <stdio.h>
#include "zlog.h"
int main(int argc, char** argv)
{
int rc;
zlog_category_t *c;
rc = zlog_init("test_hello.conf");
if (rc) {
printf("init failed\n");
return -1;
}
c = zlog_get_category("my_cat");
if (!c) {
printf("get cat fail\n");
zlog_fini();
return -2;
}
zlog_info(c, "hello, zlog");
zlog_fini();
return 0;
}
3.zlog配置文件
[formats]
simple = "%m%n"
[rules]
my_cat.DEBUG >stdout; simple
4.测试代码编译脚本
#########################################################################
# File Name: compile.sh
# Author: loon
# mail: 2453419889@qq.com
# Created Time: 2018年09月18日 星期二 18时41分55秒
#########################################################################
#!/bin/bash
CC=mipsel-openwrt-linux-gcc-4.8.3
$CC -o test_zlog test.c -I ../include -L ../lib -lzlog
编译后上传至开发板测试:
#更改执行权限
chmod +x compile.sh
#执行编译脚本
./compile.sh
#上传可执行文件及配置文件
ubuntu@ubuntu-virtual-machine:~/work/zlog/mipsel/cross_mipsel_openwrt$ scp test_zlog test_zlog.conf root@192.168.8.125:/usr/test_zlog
root@192.168.8.125's password:
test_zlog 100% 7500 7.3KB/s 00:00
test_zlog.conf 100% 63 0.1KB/s 00:00
5.开发板上运行结果
root@ZhuoTK:/usr/test_zlog# ./test_zlog
./test_zlog: can't load library 'libzlog.so.1'
缺少的libzlog.so.1库,则将交叉编译生成的lib下的libzlog.so.1库上传到板子的/lib/下即可。比如我这里使用scp上传:
ubuntu@ubuntu-virtual-machine:~/work/zlog/mipsel/lib$ scp libzlog.so.1 root@192.168.8.125:/lib/
root@192.168.8.125's password:
libzlog.so.1
然后运行发现可以了:
root@ZhuoTK:/usr/test_zlog# ./test_zlog
hello, zlog