2

I've got an application which is using both iconv functionality and libxml2.

libxml2 is installed in /usr/local, so I am using the compiler flag -I/usr/local/include. There is also a standalone libiconv installation in /usr/local which I don't want to use (I want to use the one in glibc).

Within my application code, I can sort out the iconv problem by doing:

#include </usr/include/iconv.h>

However, the problem is that the libxml2 stuff is also using iconv for it's own internal purposes. And the libxml2 headers just do:

#include <iconv.h>

Is there any way around that? For example can I do anything in my code where I am including the libxml headers, to tell it where to search for iconv?

asc99c
  • 3,815
  • 3
  • 31
  • 54

2 Answers2

1

First, include the correct <iconv.h> before any libxml2 headers, even in sources that don't use iconv. This will prevent libxml headers from including any other version (assuming the header guards are the same...).

For a long-term fix, you will need to fix your system (because it is, in fact, broken). You cannot install packages in /usr/local and then later expect to be able to enable or disable them individually. Instead, install your packages with separate prefixes. For example, install libxml2 in /opt/libxml2, and install iconv in /opt/iconv.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
  • Yep that has worked perfectly. I'll hopefully be able to sort out the machine config later on. It's a shared machine, but it was me who had set it up wrongly - I copied a project from an old AIX box where the built-in iconv was woefully lacking basic character sets (e.g. UTF-8), and so built the same GNU iconv libraries to get it working on the Linux box. – asc99c Feb 02 '12 at 09:07
0

If you do -I/usr/include -I/usr/local/include, gcc should look in /usr/include first...except that gcc treats system headers differently, so that doesn't work. As an ugly hack, you can copy /usr/include/iconv.h to a different directory and specify it in a -I flag before /usr/local/include.

William Pursell
  • 204,365
  • 48
  • 270
  • 300