Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-13-2009, 05:04 AM   #1
Registered: Jun 2009
Posts: 80
Blog Entries: 1

Rep: Reputation: 16
undefined reference to `xmlCheckVersion' in unix


I am working in unix platform. I am very new to xml parsing.. I downloaded libxml2-2.6.31.tar.gz and i installed successfully. my program is like this
1 #include <stdio.h>
2 #include <libxml/parser.h>
3 #include <libxml/tree.h>
5 static void print_element_names(xmlNode * a_node)
6 {
7 xmlNode *cur_node = NULL;
9 for (cur_node = a_node; cur_node; cur_node =
cur_node->next) {
10 if (cur_node->type == XML_ELEMENT_NODE) {
11 printf("node type: Element, name: %s\n",
12 }
13 print_element_names(cur_node->children);
14 }
15 }
17 int main(int argc, char **argv)
18 {
19 xmlDoc *doc = NULL;
20 xmlNode *root_element = NULL;
22 if (argc != 2) return(1);
24 LIBXML_TEST_VERSION // Macro to check API for match with
// the DLL we are using
26 /*parse the file and get the DOM */
27 if (doc = xmlReadFile(argv[1], NULL, 0)) == NULL){
28 printf("error: could not parse file %s\n", argv[1]);
29 exit(-1);
30 }
32 /*Get the root element node */
33 root_element = xmlDocGetRootElement(doc);
34 print_element_names(root_element);
35 xmlFreeDoc(doc); // free document
36 xmlCleanupParser(); // Free globals
37 return 0;
38 }

and make it compile as cc then i got undefined reference error as follows.
/tmp/ccEMs4sY.o: In function `example3Func':
parse.c.text+0x2c): undefined reference to `xmlReadMemory'
parse.c.text+0x67): undefined reference to `xmlFreeDoc'
/tmp/ccEMs4sY.o: In function `main':
parse.c.text+0x89): undefined reference to `xmlCheckVersion'
parse.c.text+0xe3): undefined reference to `xmlCleanupParser'
parse.c.text+0xe8): undefined reference to `xmlMemoryDump'
collect2: ld returned 1 exit status

can u help me to solve this plssss

Thankz in advance..
Old 07-13-2009, 06:57 AM   #2
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Edit: You need to link the XML library and you can use "xml2-config" to get the right compiler flags to use. See this.

Last edited by Nylex; 07-13-2009 at 07:02 AM.
Old 07-13-2009, 07:25 AM   #3
Registered: Jun 2009
Posts: 80

Original Poster
Blog Entries: 1

Rep: Reputation: 16
It works well.

Thanks a lot.
Old 07-15-2009, 10:37 AM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,808

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Moved: This thread is more suitable in <programming> and has been moved accordingly to help your thread/question get the exposure it deserves.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
undefined reference to.... crapodino Programming 1 01-13-2008 07:05 PM
undefined reference to... dimah Programming 3 12-27-2006 09:57 AM
undefined reference vkmgeek Programming 1 05-11-2006 06:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:42 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration