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

Following error occurred while compiling the 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;
}

while i am trying to go with the steps given in http://minixml.org/; parse accordingly the xml file there is certain error "undefined error to threads for dynamic library libxml.so.".

Please guide me so that i can successfully parse the xml file.

suneet saini
  • 61
  • 2
  • 7
  • 3
    It is a linking error not compilation error.You need to link to the pthread library(`-lpthread`) as well, it seems you missed it. – Alok Save May 30 '12 at 06:16
  • @Als:Is there any separate method for parsing the xml schema? In mini-xml is there some separate method for xml schema. If so; please let me know. – suneet saini May 30 '12 at 06:48

2 Answers2

2

You need to link with the pthread library using the -pthread option.

gcc -o xml XmlParser1.c -lmxml -pthread
selbie
  • 100,020
  • 15
  • 103
  • 173
1

You need to include pthread in you code. add this line at the beginning of your file

#include<pthread.h>
JMBise
  • 680
  • 4
  • 19
  • I don't think that's his problem. He's getting a linker error about an undefined reference. If he was missing the pthread.h include, he would be getting a compiler error on a specific line number. I would guess that mxml.h is including pthread.h already. – selbie May 30 '12 at 07:32