1

I am using autoconf and automake for a C++ project, and I expect that g++ will be smart enough to look at /usr/include/<library-name> when my source code already have

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

When I just run ./configure && make , I get this error

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

I have to include the library path using CCXXFLAGS this way

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

Is there a better way to write my code, Makefile or autoconf files so that g++ will look for the libraries correctly in /usr/include/<library-name> ?

Hanxue
  • 12,243
  • 18
  • 88
  • 130
  • 1
    There is a better way : `./configure CPPFLAGS=-I/usr/include/libxml2 && make`. (assuming you are using a version of autoconf that is not ancient) – William Pursell Dec 23 '12 at 17:47

1 Answers1

2

In my Makefile.am I have the following line to add g++ arguments:

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

I think that you need something like that:

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

So you also don't need to worry where the includes are located on another system.

r2p2
  • 384
  • 4
  • 14
  • I used CXXFLAGS which seemed to work. What is the prefix AM_ for? For example: CXXFLAGS=-I/usr/include/libxml2 ./configure – Hanxue Dec 19 '12 at 11:50
  • 1
    I don't know if this is a good idea. If I want to build your application, I need to know that I have to set CXXFLAGS that way. AM_CPPFLAGS is a variable inside Makefile.am. If you set it there, no one has to bother in the future. – r2p2 Dec 19 '12 at 15:57
  • 1
    No! No! No! If you are going to use `pkg-config`, then use `PKG_CHECK_MODULES`, but do not do that. (See http://stackoverflow.com/questions/10220946/pkg-check-modules-considered-harmful). If the user installs a library in a non-standard location, it is the user's responsibility to tell the compiler, and the user should set `CPPFLAGS` at configure time. It is not the package maintainer's responsibility to do basic system admin work for the user. – William Pursell Dec 23 '12 at 17:46
  • These are not arguments for `g++`. These are arguments for the preprocessor. Keep in mind that the user may be using any compiler and any preprocessor, and you must not assume `g++`, or `gcc`, or `cpp`, or any tool with which you are familiar. – William Pursell Dec 23 '12 at 17:49