LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 01-02-2010, 02:29 AM   #1
naveenisback
Member
 
Registered: Jun 2009
Posts: 80
Blog Entries: 1

Rep: Reputation: 16
linker problem in libxml2


Hi

OS:ubuntu under AMD 64
language : c/c++

I downloaded libxml2-2.6.31.tar.gz and i installed successfully. my program is like this
Code:
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 }
compilation as follows:
Code:
gcc -lxml2 -lm parser.c
but i got following errors
Code:
/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

even i included "-lxml2 -lm " linker flags, Im getting the linker error
and note that Im running under 64 bit amd processor.. is this is the problem..
Thanks in advance
 
Old 01-02-2010, 02:44 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by naveenisback View Post
Hi

OS:ubuntu under AMD 64
language : c/c++

I downloaded libxml2-2.6.31.tar.gz and i installed successfully. my program is like this
Code:
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 }
compilation as follows:
Code:
gcc -lxml2 -lm parser.c
but i got following errors
Code:
/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

even i included "-lxml2 -lm " linker flags, Im getting the linker error
and note that Im running under 64 bit amd processor.. is this is the problem..
Thanks in advance
Where ?

How do you know linker picks the correct 'libxml2' ?
 
Old 01-02-2010, 10:33 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You need to put -lxml2 and -lm at the end. gcc looks at them first and finds no dependencies so it skips over them, then it gets to your .c file.
Kevin Barry
 
Old 01-03-2010, 11:12 PM   #4
naveenisback
Member
 
Registered: Jun 2009
Posts: 80

Original Poster
Blog Entries: 1

Rep: Reputation: 16
hi

I compiled as follows
"gcc parser.c -lxml2 -lm "

Now im getting errors as follows


/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlGzfileOpenW':
(.text+0x8f6): undefined reference to `gzdopen'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlGzfileOpenW':
(.text+0x938): undefined reference to `gzopen'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlGzfileOpenW':
(.text+0x952): undefined reference to `gzopen'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlGzfileRead':
(.text+0x962): undefined reference to `gzread'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlGzfileWrite':
(.text+0x982): undefined reference to `gzwrite'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlGzfileClose':
(.text+0x9a5): undefined reference to `gzclose'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlFreeZMemBuff':
(.text+0xa18): undefined reference to `deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `__xmlParserInputBufferCreateFilename':
(.text+0x10aa): undefined reference to `gzread'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `__xmlParserInputBufferCreateFilename':
(.text+0x10d2): undefined reference to `gzrewind'
/usr/lib/gcc/x86_64-linux-gnu/4.2.4/../../../../lib/libxml2.a(xmlIO.o): In function `xmlIOHTTPCloseWrite':
(.text+0x1abb): undefined reference to `deflate'



I have downloaded libxml2 parser from this link.
http://linux.softpedia.com/progDownl...nload-162.html

do we have different kind of libxml2 parser for 64 bit and 32 bit.
if so, can u tell me where can i download libxml2 for 64 bit amd machine.

Thanks in advance
 
Old 01-04-2010, 12:49 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
It looks like you need to link to a gzip library, also. Maybe you need to add -lgz? That should go after -lxml2.
Kevin Barry
 
Old 01-04-2010, 01:19 AM   #6
naveenisback
Member
 
Registered: Jun 2009
Posts: 80

Original Poster
Blog Entries: 1

Rep: Reputation: 16
Hi ta0kira,

Thanks for ur immediate reply.

libxml2 was not completely installed.
So I did sudo apt-get -f install.
Then all the broken softwares upgraded.
Now its working fine without '-lgz'


Thanks
 
Old 01-04-2010, 08:00 PM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Yes, that makes more sense than libxml not being hard-lined to libgz, as I implied...
Kevin Barry
 
  


Reply



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
[SOLVED] cryptic linker error (i really dont like linker errors); smeezekitty Programming 2 09-19-2009 02:21 AM
Problem with libxml2-python-2.5.7 yuri16 Linux - Software 1 05-20-2009 07:59 AM
Linker problem amsampson Programming 3 05-05-2007 05:07 PM
linker problem bahadur Programming 4 11-26-2005 06:43 AM
installation problems with libxml2-2.2.66.tar.gz and libxml2-devel2-2.6.20-3.tar.gz g-string 3 Linux - Software 6 11-24-2005 11:39 AM

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

All times are GMT -5. The time now is 08:09 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
Open Source Consulting | Domain Registration