By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,110 Members | 1,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,110 IT Pros & Developers. It's quick & easy.

makefile

P: n/a
Hello

I need help with my makefile, so that when I compile my project the
source code files would be separated from the object (*.o) files.

So if I have: main.cpp and classes.cpp - the filestructure should be
like that:
project_dir/
source_dir/
main.cpp
classes.cpp
makefile
main.o
classes.o
.program_exec

My current makefile is quite good as it compiles only the source, that
is edited. Problem is that all the files are in same directory. I'd like
that the makefile should do the same thing, only with this add on that
it keeps the source files from other compiled files separeted.
#########################
# makefile #
#########################
CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=main.cpp classes.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=program_exec

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

..cpp.o:
$(CC) $(CFLAGS) $< -o $@

makfile:
Aug 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ian
Juhan Voolaid wrote:
Hello

I need help with my makefile, so that when I compile my project the
source code files would be separated from the object (*.o) files.

OT here, try comp.unix.programmer.

Ian
Aug 14 '05 #2

P: n/a
Juhan Voolaid wrote:
Hello

I need help with my makefile, so that when I compile my project the
source code files would be separated from the object (*.o) files.
As mentioned - this is OT here.

However, take a look at MakeXS. http://www.makexs.com (shameless plug).
It can do this if you need to. MakeXS is just a GNU Makefile but
rather extreme.

So if I have: main.cpp and classes.cpp - the filestructure should be
like that:
project_dir/
source_dir/
main.cpp
classes.cpp
makefile
main.o
classes.o
.program_exec

My current makefile is quite good as it compiles only the source, that
is edited. Problem is that all the files are in same directory. I'd like
that the makefile should do the same thing, only with this add on that
it keeps the source files from other compiled files separeted.
#########################
# makefile #
#########################
CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=main.cpp classes.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=program_exec

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
$(CC) $(CFLAGS) $< -o $@

makfile:

Aug 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.