在生成文件中指定库路径

Specifying Library paths in Makefile

本文关键字:路径 文件      更新时间:2023-10-16

我正在为一个C++项目使用 autoconf 和 automake,我希望 g++ 足够聪明,/usr/include/<library-name>可以在我的源代码已经有

#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <curl/curl.h>
#include <openssl/md5.h>

当我运行./configure && make时,我收到此错误

g++ -DHAVE_CONFIG_H -I. -I..   -Wall -O2   -g -O2 -MT azurefs.o -MD -MP -MF .deps/azurefs.Tpo -c -o azurefs.o azurefs.cpp
azurefs.cpp:33:26: fatal error: libxml/xpath.h: No such file or directory
compilation terminated

我必须以这种方式使用 CCXXFLAGS 包含库路径

$ CXXFLAGS=-I/usr/include/libxml2 ./configure && make

有没有更好的方法来编写我的代码、Makefile 或自动conf文件,以便 g++ 在/usr/include/<library-name>中正确查找库?

在我的 Makefile.am 中,我有以下行来添加 g++ 参数:

AM_CPPFLAGS = -I$(top_srcdir)/src/include/ --std=c++0x

我认为你需要这样的东西:

AM_CPPFLAGS = `pkg-config --cflags libxml-2.0`

因此,您也不必担心包含物位于另一个系统上的位置。