3
[root@localhost mxml-2.7]# gcc -o xml XmlParser1.c -lmxml
XmlParser1.c: In function ‘main’:
XmlParser1.c:63: warning: assignment discards qualifiers from pointer target type
/usr/local/lib/libmxml.so: undefined reference to `pthread_key_create'
/usr/local/lib/libmxml.so: undefined reference to `pthread_once'
/usr/local/lib/libmxml.so: undefined reference to `pthread_getspecific'
/usr/local/lib/libmxml.so: undefined reference to `pthread_key_delete'
/usr/local/lib/libmxml.so: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status

编译 XmlParser1.c 时发生以下错误。XmlParser1.c:

#include <stdio.h>
#include "mxml.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define MAX_SIZE 25

static mxml_node_t *xml; 
static mxml_node_t *str;
static mxml_node_t *DataSet;

static mxml_node_t *Table;
static mxml_node_t *IsAuthenticated;
static mxml_node_t *AuthenticationDate;
static mxml_node_t *Response;

int main()
{
    int fd = 0;
    char *Result=NULL;
    const char *NewResult=NULL;
    mxml_node_t *tree;
    mxml_node_t *data;
    const char *type = NULL;

    FILE *fp = fopen("/home/suneet/mxml-2.7/Sample/main.xml", "r")  ;
    if (fp == NULL)
    {
        fclose(fp);
    }
    else
    {
        fseek (fp , 0, SEEK_END);
        long settings_size = ftell (fp);
        rewind (fp);

        if (settings_size > 0)
        {
            tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
            fclose(fp);

            printf("step 1\n");
            data = mxmlFindElement(Table, tree, "diffgr:id", NULL, NULL, MXML_DESCEND);
            Result = mxmlElementGetAttr(data,"diffgr:id");
            printf("diffgr:id:%s\n",(Result == NULL)?"NULL":Result);
            mxmlDelete(data);
            mxmlDelete(tree);   
        }
    }

    return 0;
}

当我尝试按照http://minixml.org/中给出的步骤进行时;相应地解析xml文件存在某些错误“动态库libxml.so的线程未定义错误。”。

请指导我,以便我可以成功解析 xml 文件。

4

2 回答 2

2

您需要使用 -pthread 选项与 pthread 库链接。

gcc -o xml XmlParser1.c -lmxml -pthread
于 2012-05-30T07:29:44.080 回答
1

您需要在代码中包含 pthread。在文件开头添加这一行

#include<pthread.h>
于 2012-05-30T07:26:38.743 回答