0

I'm trying to use libxml2 to parse some XML files in C. To do this, after installing libxml2 developer package, I included this lines in my code.c file:

#include <libxml2/libxml/parser.h>
#include <libxml2/libxml/tree.h>

Ok, so far so good... But when I compile the code,

gcc ../src/code.c -o App

I got this message by gcc:

/usr/local/include/libxml2/libxml/parser.h:15:31: fatal error: libxml/xmlversion.h: No such file or directory
#include <libxml/xmlversion.h>
                             ^
compilation terminated.

The parser.h file included in my code.c, isn´t finding your include path "libxml/xmlversion.h", and I got the error message.

I tried to compile passing the library path with the -I parameter, without success.

Please guys, how can I solve this?

12
  • Show your exact compilation command. I guess that some -I are missing, and probably $(pkg-config --cflags libxml-2.0) Commented Aug 26, 2014 at 13:28
  • 1
    Need more information to help, how are you compiling it? Makefile? What is the build instruction that is failing? Commented Aug 26, 2014 at 13:28
  • My libxml2 files are in /usr/include/libxml2 Commented Aug 26, 2014 at 13:31
  • 1
    Please edit your question to put relevant details. If on Linux, install the libxml2 development package. Commented Aug 26, 2014 at 13:35
  • 2
    @EliasVanOotegem: not a linker issue, a compiler one. He'll get the linker issue later! Commented Aug 26, 2014 at 13:41

2 Answers 2

1

Actually, if the libxml2 is the system one (development package), it is probably known to pkg-config so the right way to compile and link (a single source file program) is:

 gcc -Wall -g $(pkg-config --cflags libxml-2.0) \
     ../src/code.c \
     $(pkg-config --libs libxml-2.0) \
     -o App

Of course you'll need to simply #include <libxml/parser.h> etc... as answered by alk

You really should use GNU make and have your Makefile, see this example (to adapt to C instead of C++, so CFLAGS instead of CXXFLAGS and CC instead of CXX...)

Take the habit to always compile with all warnings -Wall and debug info -g at least during the development phase.

Sign up to request clarification or add additional context in comments.

Comments

1

Change

#include <libxml2/libxml/parser.h>
#include <libxml2/libxml/tree.h>

to

#include <libxml/parser.h>
#include <libxml/tree.h>

and add the option -I/usr/local/include/libxml2 to the command you use for compiling.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.