ubuntu 源码编译安装log4c
1.下载源码log4c-1.2.4.tar.gz
· log4c-1.2.4.tar.gz
2.编译安装log4c
$ cd ~ #打开压缩包相应存放目录
$ tar -zxvf log4c-1.2.4.tar.gz
$ cd log4c-1.2.4
$ mkdir build
$ cd build
$ ../configure --prefix=/usr/local/log4c
$ make
$ sudo make install
3.编译log4c自带的helloworld
$ cd ~/log4c-1.2.4/example/helloworld
$ gcc -o helloworld helloworld.c -I /usr/local/log4c/include -L /usr/local/log4c/lib -llog4c
$ ./helloworld
编译成功,但是执行提示找不到liblog4c.so.3
此问题解决参考链接:
解决 sudo ldconfig /sbin/ldconfig.real: xxx 不是符号连接
4.配置文件log4crc
此时执行helloworld,程序无任何输出
cp ~/log4c-1.2.4/examples/log4crc ~/log4c-1.2.4/examples/helloworld/log4crc
并且在log4crc文件里log4c节点里追加一行配置(helloworld.c源码里指定的配置)
<category name="log4c.examples.helloworld" priority="debug" appender="stdout"/>
5.回到helloworld所在目录,运行
执行helloworld成功(该例子是在屏幕上打印一行日志)
$ ./helloworld
[stdout] ERROR log4c.examples.helloworld - Hello World!