You are not logged in.
Pages: 1
I'm trying to compile the following C file:
#include <libxml/parser.h>
int main() {
return 0;
}
with gcc (gcc calc.c -o calc).
This results in an error (error: libxml/parser.h: No such file or directory). So I changed '#include <libxml/parser.h>' to '#include <libxml2/libxml/parser.h>'. This results in many errors of the kind:
/usr/include/libxml2/libxml/parser.h:1159: error: expected '=', ',', ';', 'asm' or '__atribute__' beforce 'xmlDocPtr'
I know libxml2 is installed, I checked it with pacman and OpenBox compiles without problems. I got the error on Arch and Mac OS X. It seems like this is a pretty basic mistake I'm making (very few results with google). Can anyone point me to the right direction?
Last edited by MrAllan (2009-07-29 16:04:13)
Offline
Try
gcc -o calc calc.c $(xml2-config --cflags --libs)
This should give gcc the required flags and libraries to include.
He who says A doesn't have to say B. He can also recognize that A was false.
Offline
Leave it as <libxml/parser.h> and tell gcc to look in /usr/include/libxml2.
gcc -o calc -I/usr/include/libxml2 calc.c
Better yet, use the CFLAGS provided by xml2-config:
gcc -o calc $(xml2-config --cflags --libs) calc.c
To make things easier on yourself, consider using a Makefile.
edit: Aargh... two minutes too slow...
Last edited by Trent (2009-06-29 18:07:37)
Offline
Thanks!
Offline
Speaking of this matter,
pkg-config --cflags --libs $LIBNAME
provides a similar way for the necessary includes and flags for libraries listed in
$PKG_CONFIG_PATH
As in
/usr/lib/pkgconfig/gtk+-2.0.pc
He who says A doesn't have to say B. He can also recognize that A was false.
Offline
I followed your advice and created a makefile, but it doesn't work too well. I got this line in my makefile:
g++ -c $(CFLAGS) calc.cpp
But it only works if i define CFLAGS like so:
CFLAGS = -I/usr/include/libxml2 -lxml2 -lz -lm
And not if I define CFLAGS like so:
CFLAGS = $(xml2-config --cflags --libs)
Any ideas why this is happening?
Offline
That's because your syntax is incorrect.
use this instead:
CFLAGS := $(shell pkg-config libxml-2.0 --cflags)
LDFLAGS := $(shell pkg-config libxml-2.0 --libs)
Regards,
raf
Last edited by raf_kig (2009-08-04 19:31:35)
Offline
Pages: 1