problem with c and xml

This is a discussion on problem with c and xml within the C Programming forums, part of the General Programming Boards category; Hi all, I am currently writing a program that will involve C and libxml. The probelm is, when i run ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    49

    problem with c and xml

    Hi all,
    I am currently writing a program that will involve C and libxml. The probelm is, when i run my program, it say something like "undefined reference to '_xmlNewNode ' ", so is there any way that i can solve that.
    And i am using cygwin, i have also install the package for libxml too.


    Thanks
    Diana
    diana --> programming is tough

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    Basically, you need to tell the compiler what libraries you're using.

    Code:
    gcc prog.c -lxml
    In this case, this would cause the compiler to link with a file called libxml.a

    You need to find what your actual library is called, and adjust the command line accordingly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    This is my make file:

    Code:
    CC = gcc
     CFLAGS = -Wall -g -I/cygwin/home/Diana/ass1/ass/bin/labweek11/libxml
     LIBS = -lxml2
    
    outline:	outline.o
    	$(CC) $(CFLAGS) $(LIBS) -o $@ outline.o
    " libxml " is the folder where all the library file are. Then after i type "make", bash show
    Code:
    $ make
    gcc -Wall -g -I/cygwin/home/Diana/ass1/ass/bin/labweek11/libxml -lxml2 -o outline outli
    outline.o(.text+0x1ab): In function `main':
    /home/Diana/ass1/ass/bin/labweek11/outline.c:89: undefined reference to `_xmlNewDoc'
    outline.o(.text+0x1c5):/home/Diana/ass1/ass/bin/labweek11/outline.c:90: undefined refer
    NewNode'
    outline.o(.text+0x1e3):/home/Diana/ass1/ass/bin/labweek11/outline.c:91: undefined refer
    DocSetRootElement'
    outline.o(.text+0x230):/home/Diana/ass1/ass/bin/labweek11/outline.c:97: undefined refer
    SaveFormatFile'
    outline.o(.text+0x285): In function `process':
    /home/Diana/ass1/ass/bin/labweek11/outline.c:118: undefined reference to `_xmlNodeSetCo
    outline.o(.text+0x407):/home/Diana/ass1/ass/bin/labweek11/outline.c:150: undefined refe
    lNewTextChild'
    outline.o(.text+0x51c):/home/Diana/ass1/ass/bin/labweek11/outline.c:169: undefined refe
    lNewTextChild'
    outline.o(.text+0x556):/home/Diana/ass1/ass/bin/labweek11/outline.c:173: undefined refe
    lNewTextChild'
    outline.o(.text+0x664):/home/Diana/ass1/ass/bin/labweek11/outline.c:194: undefined refe
    lNewTextChild'
    collect2: ld returned 1 exit status
    make: *** [outline] Error 1
    Which is all the code that is written using xml.
    Can anyone help me to slove this??
    diana --> programming is tough

  4. #4
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Here's what my xml configs says.
    >xml-config --libs
    -L/usr/lib -lxml -lz
    or if you are using xml2
    >xml2-config --libs
    -L/usr/lib -lxml2 -lz -lpthread -lm
    -- Add Your Signature Here --

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    > gcc -Wall -g -I/cygwin/home/Diana/ass1/ass/bin/labweek11/libxml -lxml2
    The command line is order sensitive (read it from left to right).

    You need to list your .o files BEFORE your library files.

    Otherwise, you have no idea which symbols you need to resolve from the library (because there are none when it goes past the library).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    I change my Makefile a little, to like this
    Code:
    CC = gcc
    # CFLAGS = -Wall -g -L/cygwin/usr/include/libxml2/libxml
    CFLAGS = -Wall -g -L/cygwin/home/Diana/ass1/ass/bin/labweek11/libxml
    LIBS = -lxml2
    
    outline:	outline.o
    	$(CC) $(LDFLAGS) -o $@ outline.o $(LIBS)
    So when i compile "make", it have all this errors. It seem to me that "make" didn't detect the "LIBS", i think it wired. Have been trying to fixed this for hours already.... Can anyone see what was wrong??

    Code:
    $ make
    gcc -Wall -g -I/cygwin/usr/include/libxml2/libxml   -c -o outline.o outline.c
    outline.c:12:30: libxml/xmlmemory.h: No such file or directory
    outline.c:13:27: libxml/parser.h: No such file or directory
    outline.c:50: error: parse error before "xmlNodePtr"
    outline.c:50: warning: no semicolon at end of struct or union
    outline.c:52: error: parse error before '}' token
    outline.c:52: warning: type defaults to `int' in declaration of `Component'
    outline.c:52: warning: data definition has no type or storage class
    outline.c:54: error: parse error before "nest"
    outline.c:54: warning: type defaults to `int' in declaration of `nest'
    outline.c:54: warning: data definition has no type or storage class
    outline.c:58: error: parse error before "xmlDocPtr"
    outline.c: In function `main':
    outline.c:64: error: `xmlDocPtr' undeclared (first use in this function)
    outline.c:64: error: (Each undeclared identifier is reported only once
    outline.c:64: error: for each function it appears in.)
    outline.c:64: error: parse error before "doc"
    outline.c:65: error: `xmlNodePtr' undeclared (first use in this function)
    outline.c:89: error: `doc' undeclared (first use in this function)
    outline.c:89: warning: implicit declaration of function `xmlNewDoc'
    outline.c:90: error: `np' undeclared (first use in this function)
    outline.c:90: warning: implicit declaration of function `xmlNewNode'
    outline.c:91: warning: implicit declaration of function `xmlDocSetRootElement'
    outline.c:93: error: request for member `element' in something not a structure or union
    
    outline.c:94: error: request for member `num_children' in something not a structure or
    union
    outline.c:97: warning: implicit declaration of function `xmlSaveFormatFile'
    outline.c: At top level:
    outline.c:102: error: parse error before "xmlDocPtr"
    outline.c: In function `process':
    outline.c:107: error: `xmlNodePtr' undeclared (first use in this function)
    outline.c:107: error: parse error before "np"
    outline.c:115: error: `fin' undeclared (first use in this function)
    outline.c:118: warning: implicit declaration of function `xmlNodeSetContent'
    outline.c:118: error: request for member `element' in something not a structure or unio
    n
    outline.c:150: error: `np' undeclared (first use in this function)
    outline.c:150: warning: implicit declaration of function `xmlNewTextChild'
    outline.c:150: error: request for member `element' in something not a structure or unio
    n
    outline.c:151: error: request for member `num_children' in something not a structure or
     union
    outline.c:152: error: `temp' undeclared (first use in this function)
    outline.c:169: error: request for member `element' in something not a structure or unio
    n
    outline.c:173: error: request for member `element' in something not a structure or unio
    n
    outline.c:175: error: request for member `num_children' in something not a structure or
     union
    outline.c:194: error: request for member `element' in something not a structure or unio
    n
    outline.c:195: error: request for member `num_children' in something not a structure or
     union
    outline.c: In function `getlabel':
    outline.c:217: error: request for member `num_children' in something not a structure or
     union
    outline.c:219: error: request for member `num_children' in something not a structure or
     union
    make: *** [outline.o] Error 1
    Thanks...
    diana --> programming is tough

  7. #7
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Quote Originally Posted by dianazheng
    gcc -Wall -g -I/cygwin/home/Diana/ass1/ass/bin/labweek11/libxml -lxml2 ...
    Nice folder names lol :] ...[edit] Ohh that means assignment, I have a sick mind. :[

  8. #8
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    yap ass ==> assignment....
    No offend for that, that is just my shortcut for my assignment
    diana --> programming is tough

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    > gcc -Wall -g -I/cygwin/usr/include/libxml2/libxml -c -o outline.o outline.c
    > outline.c:12:30: libxml/xmlmemory.h: No such file or directory
    The effective path being
    /cygwin/usr/include/libxml2/libxml/libxml/xmlmemory.h

    Try say
    gcc -Wall -g -I/cygwin/usr/include/libxml2 -c -o outline.o outline.c
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    I have try each and everyone of the "CFLAGS" in my "makefile" and i am sure that i have the "libxml2.a" , "libxml2.dll.a" , "libxml2.la" and "xmlmemory.h" in the all the directory.

    Code:
    CC = gcc
    CFLAGS = -Wall -g -L/cygwin/usr/include/libxml2/libxml
    LIBS = -lxml2
    # CFLAGS = -Wall -g -I/cygwin/lib/libxml
    # CFLAGS = -Wall -g -L/cygwin/home/Diana/ass1/ass/bin/labweek11/libxml
    # CFLAGS = -Wall -g -I/usr/include/libxml2
    # CFLAGS = -Wall -g -I/usr/include/libxml
    # CFLAGS = -Wall -g -I/cygwin/usr/include/libxml2/libxml -l/cygwin/usr/include/libxml2/libxml
    # CFLAGS = -Wall -g -L/cygwin/usr/include/libxml2/libxml
    # LIBS = -lxml
    
    outline:	outline.o
    	$(CC) $(LDFLAGS) -o $@ outline.o $(LIBS)
    But i think it is wired that when i compile my "makefile", it say can't find the "/libxml/xmlmemory.h" and the "/libxml/parser.h" file.

    Code:
    $ make
    gcc -Wall -g -L/cygwin/usr/include/libxml2/libxml   -c -o outline.o outline.c
    outline.c:12:30: libxml/xmlmemory.h: No such file or directory
    outline.c:13:27: libxml/parser.h: No such file or directory
    outline.c:50: error: parse error before "xmlNodePtr"
    outline.c:50: warning: no semicolon at end of struct or union
    outline.c:52: error: parse error before '}' token
    outline.c:52: warning: type defaults to `int' in declaration of `Component'
    outline.c:52: warning: data definition has no type or storage class
    outline.c:54: error: parse error before "nest"
    outline.c:54: warning: type defaults to `int' in declaration of `nest'
    outline.c:54: warning: data definition has no type or storage class
    outline.c:58: error: parse error before "xmlDocPtr"
    outline.c: In function `main':
    outline.c:64: error: `xmlDocPtr' undeclared (first use in this function)
    outline.c:64: error: (Each undeclared identifier is reported only once
    outline.c:64: error: for each function it appears in.)
    outline.c:64: error: parse error before "doc"
    outline.c:65: error: `xmlNodePtr' undeclared (first use in this function)
    outline.c:89: error: `doc' undeclared (first use in this function)
    outline.c:89: warning: implicit declaration of function `xmlNewDoc'
    outline.c:90: error: `np' undeclared (first use in this function)
    outline.c:90: warning: implicit declaration of function `xmlNewNode'
    outline.c:91: warning: implicit declaration of function `xmlDocSetRootElement'
    outline.c:93: error: request for member `element' in something not a structure or union
    
    outline.c:94: error: request for member `num_children' in something not a structure or
    union
    outline.c:97: warning: implicit declaration of function `xmlSaveFormatFile'
    outline.c: At top level:
    outline.c:102: error: parse error before "xmlDocPtr"
    outline.c: In function `process':
    outline.c:107: error: `xmlNodePtr' undeclared (first use in this function)
    outline.c:107: error: parse error before "np"
    outline.c:115: error: `fin' undeclared (first use in this function)
    outline.c:118: warning: implicit declaration of function `xmlNodeSetContent'
    outline.c:118: error: request for member `element' in something not a structure or unio
    n
    outline.c:150: error: `np' undeclared (first use in this function)
    outline.c:150: warning: implicit declaration of function `xmlNewTextChild'
    outline.c:150: error: request for member `element' in something not a structure or unio
    n
    outline.c:151: error: request for member `num_children' in something not a structure or
     union
    outline.c:152: error: `temp' undeclared (first use in this function)
    outline.c:169: error: request for member `element' in something not a structure or unio
    n
    outline.c:173: error: request for member `element' in something not a structure or unio
    n
    outline.c:175: error: request for member `num_children' in something not a structure or
     union
    outline.c:194: error: request for member `element' in something not a structure or unio
    n
    outline.c:195: error: request for member `num_children' in something not a structure or
     union
    outline.c: In function `getlabel':
    outline.c:217: error: request for member `num_children' in something not a structure or
     union
    outline.c:219: error: request for member `num_children' in something not a structure or
     union
    make: *** [outline.o] Error 1
    Last edited by dianazheng; 05-26-2005 at 08:58 AM.
    diana --> programming is tough

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    1. If you're building within cygwin, then remove all the /cygwin from the start of paths.
    Within cygwin, everything starts with /usr

    2. libxml/xmlmemory.h
    This is
    #include <libxml/xmlmemory.h>
    right?

    In which case, you need to find the directory which contains a directory called libxml, which itself contains a file called xmlmemory.h

    On my system, such a directory is /usr/include/libxml2
    So I would say
    CFLAGS = -Wall -g -L/usr/include/libxml2

    Of course, you need to make sure you've actually installed it!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    Thanks i finally got my makefile working in cygwin....

    It should be
    Code:
    CFLAGS = -Wall -g -I/usr/include/libxml2
    diana --> programming is tough

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21