Search code examples
c++build-processautotoolsautomake

Using autotools build system / Building in a separate 'build' directory


I'm creating a software project and I wanted to use autotools to do the makefile and etc. script generation for me, I manually created Makefile.am and configure.in files, and I'm using the autogen.sh script from here. The problem comes when attempting to build the project in a separate 'build' directory, e.g. if I go:

mkdir build
cd build
../configure
make

The configure step works fine, but when running make I get:

make  all-recursive
Making all in src
/bin/sh: line 0: cd: src: No such file or directory
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Any tips to get this working? Or should I give up and try something simpler/different. I plan for this to be a reasonably simple C++ project, and the only dependency I plan to have is on the boost unit testing framework, and to do most development in Eclipse IDE.


Solution

  • there's a bug in your src/Makefile.am, line#17:

    swin-adventure_SOURCES = src/main.cc
    

    should really read:

    swin-adventure_SOURCES = main.cc
    

    since you are already in the src/ directory (unless there's a src/src/ subfolder)

    there's another bug, as you are using special characters in your _SOURCES variabes: swin-adventure_SOURCES has the forbidden - character; try to normalize that to swin_adventure_SOURCES

    finally, you are trying to assign a value to bin_PROGRAMS multiple times (and each time the same value), try to avoid that.

    something like:

    ## Additional flags to pass to aclocal when it is invoked automatically at
    ## make time. The ${ACLOCAL_FLAGS} variable is picked up from the environment
    ## to provide a way for the user to supply additional arguments.
    ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
    
    ## Define an executable target "swin-adventure", which will be installed into the
    ## directory named by the predefined variable $(bindir).
    bin_PROGRAMS = swin-adventure
    
    ## Define the list of source files for the "swin-adventure" target. The file 
    ## extension .cc is recognized by Automake, and causes it to produce rules 
    ## which invoke the C++ compiler to produce an object file (.o) from each 
    ## source file. The ## header files (.h) do not result in object files by 
    ## themselves, but will be included in distribution archives of the project.
    swin_adventure_SOURCES = main.cc