can not link against libxml2

Bug #1032639 reported by Philipp Rosenberger
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
libxml2 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

When I try tolink against libxml2 I get undefined symbol errors from libxml2. Installed packages are: libxml2 libxml2-dev

I try to build the tutorial file from libxml2: http://www.xmlsoft.org/tutorial/apc.html

I try to build the programm like this:

gcc -o main $(xml2-config --cflags --libs) main.o

on other platforms (debian testing or ubuntu 10.04) this works flawlessly.

the complete output:
$ gcc -o main $(xml2-config --cflags --libs) main.o
main.o: In function `parseStory':
main.c:(.text+0x2f): undefined reference to `xmlStrcmp'
main.c:(.text+0x4f): undefined reference to `xmlNodeListGetString'
main.c:(.text+0x73): undefined reference to `xmlFree'
main.o: In function `parseDoc':
main.c:(.text+0xa9): undefined reference to `xmlParseFile'
main.c:(.text+0xe9): undefined reference to `xmlDocGetRootElement'
main.c:(.text+0x124): undefined reference to `xmlFreeDoc'
main.c:(.text+0x13e): undefined reference to `xmlStrcmp'
main.c:(.text+0x172): undefined reference to `xmlFreeDoc'
main.c:(.text+0x197): undefined reference to `xmlStrcmp'
main.c:(.text+0x1cd): undefined reference to `xmlFreeDoc'
collect2: ld returned 1 exit status

$ xml2-config --cflags
-I/usr/include/libxml2

xml2-config --libs
-L/usr/lib/x86_64-linux-gnu -lxml2

$ ls -l /usr/lib/x86_64-linux-gnu/libxml2.*
-rw-r--r-- 1 root root 2187982 May 18 21:52 /usr/lib/x86_64-linux-gnu/libxml2.a
-rw-r--r-- 1 root root 947 May 18 21:52 /usr/lib/x86_64-linux-gnu/libxml2.la
lrwxrwxrwx 1 root root 16 May 18 21:52 /usr/lib/x86_64-linux-gnu/libxml2.so -> libxml2.so.2.7.8
lrwxrwxrwx 1 root root 16 May 18 21:52 /usr/lib/x86_64-linux-gnu/libxml2.so.2 -> libxml2.so.2.7.8
-rw-r--r-- 1 root root 1417368 May 18 21:52 /usr/lib/x86_64-linux-gnu/libxml2.so.2.7.8

$ nm -D /usr/lib/x86_64-linux-gnu/libxml2.so |grep -e xmlStrcmp -e xmlNodeListGetString -e 'xmlFree$' -e xmlParseFile -e xmlDocGetRootElement -e 'xmlFreeDoc$'
0000000000054bd0 T xmlDocGetRootElement
0000000000358a08 D xmlFree
00000000000537e0 T xmlFreeDoc
0000000000051d50 T xmlNodeListGetString
000000000004e370 T xmlParseFile
00000000000aa9b0 T xmlStrcmp

Revision history for this message
Philipp Rosenberger (philipp-rosenberger) wrote :

Ubuntu version is 12.04 as amd64 and as x86.

Revision history for this message
Jason Conti (jconti) wrote :

Thanks for the bug report. With the changes to the linker in 11.10+, you must be sure when compiling to specify the -llibrary arguments after the objects that reference them.

In the case above:

gcc -o main $(xml2-config --cflags --libs) main.o

should be:

gcc -o main main.o $(xml2-config --cflags --libs)

so that the -llibrary args end up at the end of the command line. Please see http://wiki.debian.org/ToolChain/DSOLinking
for an overview of the changes.

Changed in libxml2 (Ubuntu):
status: New → Invalid
Revision history for this message
marcond@gmail.com (marcond) wrote :

I had the same problem when compiling libxenserver-6.0.0-1-src. The solution was the same as above, i.e. changing the line 65 of the Makefile like this:

 $(CC) $(LDFLAGS) -o $@ $< -L . -lxenserver

becomes:

 $(CC) -o $@ $< -L . -lxenserver $(LDFLAGS)

Then the compilation worked just fine.

Diff:
-----------------------
@@ -62,7 +62,7 @@
  $(AR) rcs libxenserver.a $^

 $(TEST_PROGRAMS): test/%: test/%.o libxenserver.so
- $(CC) $(LDFLAGS) -o $@ $< -L . -lxenserver
+ $(CC) -o $@ $< -L . -lxenserver $(LDFLAGS)

 .PHONY: install
-----------------------

Revision history for this message
whitis (whitis) wrote :

This unacceptable change in the linker has the potential to break many packages. Especially when:
cc=gcc $(include) $(libs)
prog1: prog1.c

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

This is an intentional toolchain change, which brings significant benefits and features to Ubuntu. Similar changes are adopted by other distributions such as Debian and Fedora. Here are further details:

https://wiki.debian.org/ToolChain/DSOLinking

http://fedoraproject.org/wiki/UnderstandingDSOLinkChange

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.