Re: [xml] The order of arguments when compiling



Hi,

xmlparsefile_SOURCES = main.c
xmlparsefile_LDFLAGS = `xml2-config --libs`

are you aware of the LIBS option?

xmlparsefile_LIBS = ...

This should allow for the approriate ordering.

Christian

xmlparsefile_CFLAGS = -Wall -Wextra `xml2-config --cflags`

I think it's strange that GNU Automake do this choice if this is not compatible with most Unix linkers...

I will ask the GNU Automake mailing list to know if there is a way to set a different argument order than 
the default.

Any other suggestion is welcome.

----- Mail original -----
De: "Csaba Raduly" <rcsaba gmail com>
À: "spam spam spam spam" <spam spam spam spam free fr>
Cc: xml gnome org
Envoyé: Vendredi 17 Février 2012 09:55:52
Objet: Re: [xml] The order of arguments when compiling

Hi spam,

On Thu, Feb 16, 2012 at 4:01 PM,   wrote:
Hello,

On a first computer, when I compile a C program using the libxml2 library I do :
$ gcc `xml2-config --cflags` `xml2-config --libs` main.c
or
$ gcc main.c `xml2-config --cflags` `xml2-config --libs`
And it works (but the first method is better because it respects the order of arguments in the gcc 
manual).

On a second computer, if I compile like this, there is an error :
$ gcc `xml2-config --cflags` `xml2-config --libs` main.c
/tmp/cc7uNwed.o: In function `parseDoc':
main.c:(.text+0xd): undefined reference to `xmlParseFile'
main.c:(.text+0x51): undefined reference to `xmlCleanupParser'
main.c:(.text+0x63): undefined reference to `xmlFreeDoc'
main.c:(.text+0x68): undefined reference to `xmlCleanupParser'
collect2: ld returned 1 exit status
But if I compile like this, there is no error :
$ gcc main.c `xml2-config --cflags` `xml2-config --libs`

I thought this was a gcc problem but someone on the gcc mailing-list tell me that probably I have 
compiled libxml2 on the second computer "statically". And I should compile it "dynamically". It's true 
that on the second computer, I have compiled myself the library (configure, make, make install). On the 
first computer, this is my distro package.

How should I compile libxml2 on the 2nd computer to have the same behavior on the two computers?

You shouldn't; just use the last compilation command (with
`xml2-config --libs` at the end).
Most Unix linkers are one-pass; because of this, an object which needs
a symbol must appear before the object (or library) which supplies
that symbol.

See for example http://webpages.charter.net/ppluzhnikov/linker.html

GNU make's built-in rule for linking boils down to:

%: %.c
#  commands to execute (built-in):
         $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)      $^
    $(LOADLIBES) $(LDLIBS) -o $@

%: %.o
        $(CC) $(LDFLAGS) $(TARGET_ARCH)      $^      $(LOADLIBES)
$(LDLIBS) -o $@

As you can see, the list of source or object files ($^) is always
_before_ the list of libraries (in $(LDLIBS) or $(LOADLIBES) ).

Hope this helps,
Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]