log4c交叉编译问题解决及简单应用

来源:互联网 发布:simatic it 软件下载 编辑:程序博客网 时间:2024/06/05 21:59

在x86上面编译log4c很简单. 下载log4c-1.2.1.tar.gz, 解压,

./configuremakemake install

That’s OK!
下面说一下交叉编译log4c遇到的问题. 我的./configure如下:
/mnt/share_disk/program-source/log4c-1.2.1/configure –-prefix=/mnt/share_disk/program-files/log4c-ppc/  CC=ppc_82xx-gcc –host=ppc
首先出现如下问题: error: expat.h: No such file or directory

expat是什么东西呢? Expat is James Clark’s Expat XML parser library in C. It is a stream oriented parser that requires setting handlers to deal with the structure that the parser discovers in the document.

解决方法1: 下载expat源代码, 编译安装到某个路径下面, 然后在configure时用–with-expat-prefix指定所安装的路径.

解决方法2: 直接–without-expat, 这时log4c将自己用yacc and lex for parsing xml, 我直接用该方法.反正对解析效率没有要求.

接下来的问题是: undefined reference to `rpl_realloc` undefined reference to `rpl_malloc`.

原来, 交叉编译时, 会将下面三个变量设为no, 我们强行设置为yes即可. 在configure前执行

export ac_cv_func_realloc_0_nonnull=${ac_cv_func_realloc_0_nonnull=yes}export ac_cv_func_realloc_works=${ac_cv_func_realloc_works=yes}export ac_cv_func_malloc_0_nonnull=yes
简单示例如下:

#include "log4c.h"int main(){    int i = 0;    if (log4c_init()) {        printf("aaaaaaaaaaa");        return 0;    }    log4c_category_t* mycat = log4c_category_get("octeon_cat");    printf("mycat %p.\n", mycat);    while (1) {        log4c_category_log(mycat, LOG4C_PRIORITY_DEBUG, "Hello World!, %d", i);        i++;        if (i >= 1000)            break;     }     return 0;}

xml配置文件如下:

<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE log4c SYSTEM ""><log4c version="1.2.1">    <config>        <bufsize>0</bufsize>        <debug level="2"/>        <nocleanup>0</nocleanup>        <reread>1</reread>    </config>    <!-- root category ========================================= -->    <category priority="notice"/>    <category priority="debug" appender="octeon_appender"/>    <!-- default appenders ===================================== -->    <appender layout="basic"/>    <appender layout="dated"/>    <appender layout="basic"/>    <rollingpolicy maxsize="1048576" maxnum="10" />    <appender logdir="./" prefix="octeon_mgmt" layout="dated" rollingpolicy="octeon_roll" />    <!-- default layouts ======================================= -->    <layout/>    <layout/></log4c>