Question about placing output to a specific directory

Perry Smith
Mon Apr 10 18:01:00 GMT 2006

How about writing a shell script front end that would compile each  
file separately?

It may help us to help you if we understood why compiling separately  
or moving the .o's does not work for you.


On Apr 10, 2006, at 12:40 PM, Louie McCrady wrote:

> g++ can take a collection of .cpp file names and compile them.  I have
> not found a way to direct the placement of the resulting .o files to a
> specific directory.  Is there an option that allows you to specify the
> directory where the .o files will be placed?
> When I compile a collection of .cpp files at one time, the .o files go
> to the current working directory.  I would like to have them placed in
> an /obj directory somewhere else.
> I do not want to compile each .cpp file separately specifying both the
> input and output file locations.
> I do not want to compile to the current directory, then move the .o
> files to a separate /obj directory with a mv command.
> I've tried changing the current directory to the ./obj directory, but
> this throws off the location to other source, header, and lib files in
> other relative directories.  This does not appear to be a practical
> solution.
> I need something like this:
> g++ -c foo1.cpp foo2.cpp foo3.cpp -o ./obj/
> where foo1.o foo2.o foo3.o get placed in ./obj/ off the current  
> working
> directory.
> Any help would be greatly appreciated.
> Thank you,
> Louie.

More information about the Gcc-help mailing list