How to compile sources file and save object files into a separate directory

From: Rainbow Fish (rainbowfish888_at_yahoo.com)
Date: 12/29/03


Date: 29 Dec 2003 07:19:00 -0800

Hi there,

I am building a make file to compile many .cpp files in different
directories, and save .o files into one directory. All source file
names are different.

For example:
/prj/cmn/cmn.cpp
/prj/prj1/prj1.cpp
/prj/prj1/main.cpp

Save .o files to
/out/prj1/cmn.o
/out/prj1/prj1.o
/out/prj1/main.o

I trid to do it like this,

SOURCES := /prj/cmn/cmn.cpp /prj/prj1/prj1.cpp /prj/prj1/main.cpp
OBJECTS := $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir
$(SOURCES)))))

all: /out/prj1/prj1

/out/prj1/prj1 : $(OBJECTS)
        $(LINK.cpp) $(DBG_OPTS) -o /out/prj1/prj1 $(OBJECTS)

/out/prj1/%.o : %.cpp
        $(COMPILE.cpp) $(DBG_OPTS) -o $@ $<

But it does not work.
Please help me. Thanks in advance.



Relevant Pages

  • Re: Looking for a free basic compiler for DOS
    ... mother of an ide file - and created separate source files for each SUB ... big to compile in one bc step. ... the source for all the SUBS in the same source file. ...
    (comp.lang.basic.misc)
  • Re: disabling parse error in gcc
    ... typedef struct MYSTRUCT{ ... it will compile correctly. ... A header file shall permit multiple inclusion of itself. ... so that a source file containing only TWO #includes of it will compile, ...
    (comp.unix.programmer)
  • Re: A funny yet crazy extreme test on Delphi 7 compiler
    ... The RAM is 1G. ... A project with a major source file names TestCase.pas. ... Delphi can compile crazy functions with 999 parameters. ...
    (borland.public.delphi.non-technical)
  • Re: Summary: translation units, preprocessing, compiling and linking?
    ... > proper, assembly and linking, always in that order. ... that specifies that a file have a particular extension, ... you can call your main source file ... something a source file is if you instruct your compiler to compile it. ...
    (comp.lang.cpp)
  • Re: automatically remove unused #includes from C source?
    ... compile error, then the tool cannot assume that file1.h is a -necessary- ... I don't mechanically automate the code change and test process. ... by source file) and check to see whether ... Once you get beyond standard C into POSIX or system dependancies, ...
    (comp.lang.c)