mipsel-openwrt-linux交叉编译zlog日志库并测试

mipsel-openwrt-linux交叉编译zlog日志库并测试


一、准备

GitHub:https://github.com/HardySimpson/zlog

https://github.com/bmanojlovic/zlog

正常linux下编译安装测试指导:
http://hardysimpson.github.io/zlog/

交叉编译指导:
https://blog.csdn.net/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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称系统有问题

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值