I was learning GNU autotools (autoconf, automake) with this helloworld example. My project tree is like this:
|-- aclocal.m4
|-- AUTHORS
|-- autom4te.cache
| |-- output.0
| |-- output.1
| |-- requests
| |-- traces.0
| `-- traces.1
|-- autoscan.log
|-- ChangeLog
|-- config.h.in
|-- configure
|-- configure.ac
|-- COPYING
|-- depcomp
|-- include
| |-- hello.hpp
| `-- world.hpp
|-- INSTALL
|-- install-sh
|-- lib
| |-- hello.cpp
| |-- Makefile.am
| |-- Makefile.in
| `-- world.cpp
|-- Makefile.am
|-- Makefile.in
|-- missing
|-- NEWS
|-- README
`-- src
|-- main.cpp
|-- Makefile.am
`-- Makefile.in
I build like this:
$autoreconf -vfi
$./configure
$make
... and get a compilation failure:
Making all in src make[2]: Entering directory `/home/suddin/package_directory/src' g++ -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cpp main.cpp:7:21: fatal error: hello.hpp: No such file or directory #include "hello.hpp" ^
I was able to build successfully by changing my #include
directives to these:
#include "../include/hello.hpp"
#include "../include/world.hpp"
, but I would prefer to keep them as they are:
#include "hello.hpp"
#include "world.hpp"
My src/Makefile.am
file contains the following line; why does it not resolve the issue?
helloWorld_CXXFLAGS=-I../include ##Add path to header file
For context, here are all my Makefile.am files:
===== src/Makefile.am ======================
bin_PROGRAMS=helloworld
helloworld_SOURCES=main.cpp
helloworld_CXXFLAGS= -I../include ## add path to headerfiles
helloworld_LDADD=../lib/libhw.a ## link with static library
===== lib/Makefile.am =======================
noinst_LIBRARIES=libhw.a ## static library which is not to be installed
libhw_a_SOURCES=hello.cpp hello.hpp world.cpp world.hpp
libhw_a_CXXFLAGS=-I../include ## add path to headerfiles
===== Makefile.am (top level) =================
SUBDIRS=lib src ## processing subdirs in given order
make
issues for filemain.cpp
does not include the needed-I
directive. This is the proximal cause of the compilation error. I also note that your question has inconsistent name capitalization: the text says you've set amake
variable namedhelloWorld_CXXFLAGS
(with a capital 'W'); if indeed you have done so then that is irrelevant to building a target namedhelloworld
(with lowercase 'w'). Yoursrc/Makefile.am
uses the appropriate capitalization, however. – John BollingerMakefile.am
files you have presented, and I was unable to use them as a model for reproducing the error. I am therefore inclined to suspect that the actual situation is different in some way than you have presented. Perhaps one or more variable names really are wrong, or perhaps you did not really re-runautoreconf
since the last time you modified yourMakefile.am
files (and you have maintainer mode disabled). – John Bollinger