0

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?

Mostafa Barmshory
  • 1,849
  • 24
  • 39
  • You should take a moment to consider an important question: Why? I can understand not wanting to or not being able to record compilation results in the source directory, but that's not what you seem to be trying to avoid. For most intents and purposes, the location of the `.o` files *doesn't matter*. Neither, really, does the build location of the executables -- it's just where the compiler drops them until such time as you perform a `make install`. – John Bollinger Apr 23 '20 at 00:10

1 Answers1

4

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.

MadScientist
  • 92,819
  • 9
  • 109
  • 136