Constantinvs
Constantinvs

Reputation: 3

header file (.h) include problems with gcc

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?

Upvotes: 0

Views: 2239

Answers (2)

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.

Upvotes: 1

alk
alk

Reputation: 70931

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.

Upvotes: 1

Related Questions