Re: [xml] The order of arguments when compiling



Thank you for this option.
But if I use it like this :
bin_PROGRAMS = xmlparsefile
xmlparsefile_SOURCES = main.c
xmlparsefile_LDADD = `xml2-config --libs`
xmlparsefile_CFLAGS = -Wall -Wextra `xml2-config --cflags`

I got :
$ autoreconf
src/Makefile.am:3: linker flags such as `--libs`' belong in `xmlparsefile_LDFLAGS
make: *** [Makefile.in] Error 1

Are you sure about "_LDADD" now?

----- Mail original -----
De: "Christian Engwer" <christian engwer uni-muenster de>
Ã: "spam spam spam spam" <spam spam spam spam free fr>
Cc: xml gnome org
EnvoyÃ: Vendredi 17 FÃvrier 2012 15:48:00
Objet: Re: [xml] The order of arguments when compiling

On Fri, Feb 17, 2012 at 01:12:04PM +0100, spam spam spam spam free fr wrote:
Indeed, I don't know this option.
But, if I use it in my Makefile.am:
bin_PROGRAMS = xmlparsefile
xmlparsefile_SOURCES = main.c
xmlparsefile_LIBS = `xml2-config --libs`
xmlparsefile_CFLAGS = -Wall -Wextra `xml2-config --cflags`

The compile does now :
$ gcc -DPACKAGE_NAME=\"xmlparsefile\" -DPACKAGE_TARNAME=\"xmlparsefile\" -DPACKAGE_VERSION=\"0.1\" 
-DPACKAGE_STRING=\"xmlparsefile\ 0.1\" -DPACKAGE_BUGREPORT=\"samson pierre etud univ-montp2 fr\" 
-DPACKAGE_URL=\"\" -DPACKAGE=\"xmlparsefile\" -DVERSION=\"0.1\" -I.    -Wall -Wextra `xml2-config --cflags` 
-g -O2 -MT xmlparsefile-main.o -MD -MP -MF .deps/xmlparsefile-main.Tpo -c -o xmlparsefile-main.o `test -f 
'main.c' || echo './'`main.c
mv -f .deps/xmlparsefile-main.Tpo .deps/xmlparsefile-main.Po

So, it does something like this :
$ gcc -Wall -Wextra `xml2-config --cflags` main.c

And I got the same error.

The "`xml2-config --libs`" has completely disappeared.

Are you sure about _LIBS option?

Oh sorry... it is _LDADD.

Christian

----- Mail original -----
De: "Christian Engwer" <christian engwer uni-muenster de>
Ã: "spam spam spam spam" <spam spam spam spam free fr>
Cc: xml gnome org
EnvoyÃ: Vendredi 17 FÃvrier 2012 12:42:41
Objet: 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
_______________________________________________
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]