[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 文件。
最佳答案
您需要使用 -pthread 选项链接到 pthread 库。
gcc -o xml XmlParser1.c -lmxml -pthread
关于c - 用 C 编译 Xml 解析器时出现线程错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10810877/