日志工具zlog交叉编译至imx下位机运行

2018-11-22  白微linux

zlog的官网http://hardysimpson.github.io/zlog/git

zlgo github源码下载网https://github.com/HardySimpson/zlog/releasesgithub

有网友提供了以下版本,方便其余平台上安装编译,很是感谢!工具

auto tools版本: https://github.com/bmanojlovic/zlog测试

我下载的auto tools版本ui

 

PC端(Ubuntu)url

首先查看下是否已经具备交叉编译环境spa

echo $PATH.net

我这里是显示带有"/opt/poky/../arm-poky-linux-gnueabi"code

而后能够去编译源码

cd 到源码目录

unzip zlog-master.zip
cd zlog-master/
mkdir install
chmod +x autogen.sh
./autogen.sh
./configure --host=arm-poky-linux-gnueabi --prefix=/.../zlog/zlog-master/install/
make install

此时已经编译成功至当前目录下的install目录里

进去zlog_install目录的lib里,查看是否已是你的下位机适用库

file libzlog.so.1.1.0
显示:libzlog.so.1.1.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=59cdf007aadd8a298b9f8a7f9df54b7f3919174a, not stripped

表示已是下位机可执行的zlog库;该工具已经编译成功,将install里面的东西打包成.gz文件 tar czvf zlog_master.tar.gz install/,scp 给下位机直接解压到根目录下

 

接下来开始编写测试程序:

mkdir zlog_test

cd zlog_test

touch test_hello.c

vi test_hello.c

 1 #include <stdio.h> 
 2 
 3 #include "zlog.h"
 4 
 5  
 6 
 7 int main(int argc, char** argv)  8 
 9 { 10 
11     int rc; 12 
13     zlog_category_t *c; 14 
15     rc = zlog_init("test_hello.conf"); 16 
17     if (rc) { 18 
19         printf("init failed\n"); 20 
21         return -1; 22 
23  } 24 
25     c = zlog_get_category("my_cat"); 26 
27     if (!c) { 28 
29     printf("get cat fail\n"); 30 
31  zlog_fini(); 32 
33         return -2; 34 
35  } 36 
37     zlog_info(c, "hello, zlog"); 38 
39  zlog_fini(); 40 
41     return 0; 42 
43 }

 

在同目录下新建test_hello.conf,编辑输入

[formats] simple = "%m%n" [rules] my_cat.DEBUG >stdout; simple

在同目录下新建Makefile

all:clean test test_hello.o test_hello test: $(CC) -o test test.c test_hello.o: $(CC) -c -o test_hello.o test_hello.c -I/../zlog-master/install/include test_hello: $(CC) -o test_hello test_hello.o -L/../zlog-master/install/lib -lzlog -lpthread clean: rm -f test test_hello.o test_hello

执行make,生成 test_hello

将test_hello和test_hello.conf拷贝至下位机,直接运行./test_hello,打印成功

# ./test_hello hello, zlog

相关文章
相关标签/搜索