473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

makefile

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
2 2996
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
1
by: Jamie Saker | last post by:
I think I'm overlooking something assumed in socket's makefile method. Googling several hours and digging thru the python reference didn't help - I think I'm overlooking an assumption between...
4
by: newbiecpp | last post by:
I am very sorry to post this one because I know it is out of topic but I cannot find the proper news group. I understand that most senior C++ programmers know makefile very well. My question is...
4
by: Sharp Tool | last post by:
Hi I have downloaded a program that is written in C++ that I would like to compile into a Win XP executable. The program contains a Makefile written for Unix/linux/cygwin. I would like to...
4
by: Jess | last post by:
Hello, I am now trying to use makefile to compile C++ programs. My makefile looks like: f1.o : f1.cpp h1.h h2.h g++ -c f1.cpp f2.o : f2.cpp h2.h h3.h g++ -c f2.cpp
8
by: xz | last post by:
I am a rookie of C++ and got so confused with the Makefile these days. Could anyone be so kind and give a little sample Makefile for the following particular example? Let's say I have the...
1
by: rpjanaka | last post by:
I am using an open source library called IGI_UDP for measure the available bandwidth of a link (http://www.cs.cmu.edu/%7Ehnn/igi/ ). with that library they have provided a "Makefile" which is not an...
5
by: M.Liang Liu | last post by:
I have a project with the following dirs: --------------------------------------------------------------------------------------- +src |-proj0 |-program1 |-program2 |-proj1 |-program1...
2
by: chutsu | last post by:
I'm basically a summer student working on a program called Rivet. (http://projects.hepforge.org/rivet/) And I'm trying to port it to BOINC so that the hosts can download the BOINC client and do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.