LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

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


Hi

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>
4
5 static void print_element_names(xmlNode * a_node)
6 {
7 xmlNode *cur_node = NULL;
8
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",
cur_node->name);
12 }
13 print_element_names(cur_node->children);
14 }
15 }
16
17 int main(int argc, char **argv)
18 {
19 xmlDoc *doc = NULL;
20 xmlNode *root_element = NULL;
21
22 if (argc != 2) return(1);
23
24 LIBXML_TEST_VERSION // Macro to check API for match with
// the DLL we are using
25
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 }
31
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 parser.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, 07:57 AM   #2
Nylex
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 08:02 AM.
 
Old 07-13-2009, 08:25 AM   #3
naveenisback
Member
 
Registered: Jun 2009
Posts: 80

Original Poster
Blog Entries: 1

Rep: Reputation: 16
It works well.

Thanks a lot.
 
Old 07-15-2009, 11:37 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

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


Reply


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 01:15 AM
undefined reference to.... crapodino Programming 1 01-13-2008 08:05 PM
undefined reference to... dimah Programming 3 12-27-2006 10:57 AM
undefined reference vkmgeek Programming 1 05-11-2006 07:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 04:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 PM.

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