gcc/g++ option to place all object files into separate directory

后端 未结 10 573
无人及你
无人及你 2020-11-30 19:44

I am wondering why gcc/g++ doesn\'t have an option to place the generated object files into a specified directory.

For example:

mkdir builddir
mkdir          


        
10条回答
  •  心在旅途
    2020-11-30 20:25

    This is among the problems autoconf solves.

    If you've ever done ./configure && make you know what autoconf is: it's the tool that generates those nice configure scripts. What not everyone knows is that you can instead do mkdir mybuild && cd mybuild && ../configure && make and that will magically work, because autoconf is awesome that way.

    The configure script generates Makefiles in the build directory. Then the entire build process happens there. So all the build files naturally appear there, not in the source tree.

    If you have source files doing #include "../banana/peel.h" and you can't change them, then it's a pain to make this work right (you have to copy or symlink all the header files into the build directory). If you can change the source files to say #include "libfood/comedy/banana/peel.h" instead, then you're all set.

    autoconf is not exactly easy, especially for a large existing project. But it has its advantages.

提交回复
热议问题