17

I am on Debian 8 (Jessie), 64 Bit. I installed libxml2-dev, which now sits in /usr/include/libxml2/libxml.

But when I do (just like libxml docs say)

#include <libxml/parser.h>

I only get when compiling (with gcc)

fatal error: libxml/parser.h: no such file or directory

Notes: On another machine, with an old 64 Bit Suse, where libxml2-dev sits in the exact same path and no other environment vars are set compared to the new Debian, it works perfectly fine. Problem occured while migrating from one to another computer using the exact same makefiles. All other -dev libs that I need just worked (with their documented #include <path>) after the migration (they were all installed with apt-get), only libxml2-dev is not found on compilation.

Do I need to do anything else to make libxml2-dev visible?

Foo Bar
  • 1,764
  • 4
  • 24
  • 43

6 Answers6

14

If you installed it: sudo apt-get install libxml2-dev libxml2-doc go into /usr/include/libxml2 and copy or move all content from that folder on a level below: cp -R libxml/ ../ After this for me it works.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
Volodymyr
  • 1,192
  • 21
  • 42
11

Try to compile with explicite inclusion where the parser.h file is, i.e. smth like this

g++ -I/usr/include/libxml2/


Following environment variables can also be used for lookup of header files

CPATH
C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
OBJC_INCLUDE_PATH

Find more information here

deimus
  • 9,565
  • 12
  • 63
  • 107
  • Well, this works obviously. But what *could be* the reason that the lib is found on one system but not the other when sitting in the exact same place using the exact same makefile? – Foo Bar Apr 24 '15 at 12:50
  • Aparently the `INCLUDE_PATH` environment variable is not updated to include also the `/usr/include/libxml2/` – deimus Apr 24 '15 at 12:53
  • just check it with `echo $INCLUDE_PATH` – deimus Apr 24 '15 at 12:55
  • This var does not exist at all, on both machines. – Foo Bar Apr 24 '15 at 12:55
  • And `C_INCLUDE_PATH` ? – deimus Apr 24 '15 at 12:56
  • Or to shorten this: On both machines, there's no env var that has anything with `*INCL*` or a path with `*incl*` in it. – Foo Bar Apr 24 '15 at 12:59
  • Run following command " \`gcc -print-prog-name=cc1plus\` -v " to see where gcc is looking for header files – deimus Apr 24 '15 at 13:00
  • On both theres `/usr/include` in the list (and some other ones in completly different places), but none with subfolder `libxml2`. – Foo Bar Apr 24 '15 at 13:04
  • Thats the reason why it does not find the header by default, check the answer again I've updated it on how to modifty the default header files lookup behavior – deimus Apr 24 '15 at 13:10
  • But why does it work on the old Suse Linux where all this is missing as well? – Foo Bar Apr 24 '15 at 13:16
  • The configurations on both system cannot be the same as its working on one host but not working on another host. The reasons can be many, e.g. wrongly configured and installed `libxml` on your new host. Or `OS` specific changes. Just try to check if the lib installed exactly to same directories on both systems. – deimus Apr 24 '15 at 13:18
4

I came across this same problem on a Centos system. I resolved it by doing the following:

yum install libxml2-devel
cd /usr/include
ln -s libxml2/libxml .

That was it. No change to environment variables or compiler switches.

Pat
  • 109
  • 4
  • This worked for me, but feels like a hack. I understand what's happening, but why is it needed? – Brean Nov 02 '22 at 12:49
1

You should use pkg-config to pass parameters to compiler. Like this

g++ `pkg-config --cflags libxml-2.0` example.c -o example.o

and to linker:

g++ `pkg-config --libs libxml-2.0` example.o -o example
BЈовић
  • 62,405
  • 41
  • 173
  • 273
0

I was facing the same issue in Ubuntu 20.04 Renamed /usr/include/libxml2 to /usr/include/libxml2_bak worked for me.

imok1948
  • 81
  • 1
  • 3
0

Yeah. The issue for me across multiple OS versions is that the package installed with apt-get puts the code into the folder

/usr/include/libxml2/libxml/

You can't just move the libxml code up a directory and reference include the headers with libxml2/headerfile.h because some of the code files are pre-built to use the libxml include path.

I'm able to fix it without issue using a symlink.

cd /usr/include
sudo ln -s /usr/include/libxml2/libxml/ ./libxml

This will make it so that you can compile just using the simple

gcc main.c -lxml2