Search code examples
cubuntulibxml2

libxml for c program in ubuntu


I want to use libxml2 as parser for a c program on a system with ubuntu. I used the following command to install libxml2:

sudo apt-get install -y libxml2-dev

I try to compile the following file: http://xmlsoft.org/examples/reader1.c My makefile looks like this:

xml_reader: xml_reader.o
    gcc -o xml_reader xml_reader.o -lxml2 -lm
    
xml_reader.c: xml_reader.c
    gcc -c xml_reader.c -I/usr/include/libxml2
    

But sadly I get the following response:

fatal error: libxml/xmlreader.h: No such file or directory

Did I miss something, which I had to do before compiling or am I even using the right -l argument?


Solution

  • The target of your second Makefile rule should be xml_reader.o and not xml_reader.c. Right now make is using a default rule instead which does not make use of -I/usr/include/libxml2 and thus gcc cannot find the required header.