Unable to compile using libxml

I have a source file that I can run through the terminal using

gcc source.c -I/usr/include/libxml2 -lxml2 -o output 

but when I #include source file that contains the libxml source files, the compiler complains that libxml/xmlmemory.h: libxml/parser.h: libxml/xpath.h cannot be found: there is no such file or directory.

+6
c libxml2
source share
3 answers

You always need to store -I/usr/include/libxml2 in your gcc statement so that it can find the header files.

+5
source share

You can also use xml2-config --cflags --libs to extract the compilation flags to add.

 kjp@vbox :~/Dev/ScratchDir$ xml2-config --cflags --libs -I/usr/include/libxml2 -lxml2 kjp@vbox :~/Dev/ScratchDir$ 
+3
source share

It seems that the source is linking to libxml and not to libxml2. You can check that

 /usr/include/libxml2/libxml/xmlmemory.h 

really available? (try viewing it)

You do not compile headers, headers should only be available as a "description" of what libraries implement

0
source share

All Articles