Search code examples
makefilegnuautotools

How to change *.o file and product directory by using GNU Autotools?


I create a very simple hello world C/C++ project by GNU Autotools. Here is a full tutorial shows how to build the simplest project in GNU Autotools. I want to change the project to store all *.o in build/ directory and the executable file in output/.

Is it possible to change the output folder of C/C++ compiler in Autotools?


Solution

  • That isn't how autotools is designed. The way autotools is designed is that you leave the source files where they are and change to another directory and run your build there, and it will write object files locally.

    So, instead of running:

    cd myproj
    ./configure
    make
    

    and getting the object files in the same directory as the sources, you do something like:

    mkdir obj
    cd obj
    ../myproj/configure
    make
    

    and then the object files live in the obj directory, not in the source directory.