如何修改特定包含的包含路径
我有一个同时使用 iconv 功能和 libxml2 的应用程序。
libxml2 安装在 /usr/local
中,因此我使用编译器标志 -I/usr/local/include
。在 /usr/local
中还有一个独立的 libiconv 安装,我不想使用它(我想使用 glibc 中的那个)。
在我的应用程序代码中,我可以通过执行以下操作来解决 iconv 问题:
#include </usr/include/iconv.h>
但是,问题是 libxml2 内容也将 iconv 用于其自身的内部目的。 libxml2 标头就是这样做的:
#include <iconv.h>
有什么办法解决这个问题吗?例如,我可以在代码中执行包含 libxml 标头的任何操作,以告诉它在哪里搜索 iconv 吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,在任何 libxml2 标头之前包含正确的
,即使在不使用 iconv 的源中也是如此。这将阻止 libxml 标头包含任何其他版本(假设标头防护相同......)。对于长期修复,您将需要修复您的系统(因为它实际上已损坏)。您无法将软件包安装在
/usr/local
中,然后期望能够单独启用或禁用它们。相反,请使用单独的前缀安装软件包。例如,在/opt/libxml2
中安装 libxml2,在/opt/iconv
中安装 iconv。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
.如果您执行
-I/usr/include -I/usr/local/include
,gcc 应该首先查找 /usr/include...除了 gcc 对待系统标头的方式有所不同,因此不会工作。作为一个丑陋的黑客,您可以将 /usr/include/iconv.h 复制到另一个目录,并在 /usr/local/include 之前的 -I 标志中指定它。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.