Hi,
i am trying to create a makefile for my C++ program. when i say "make" it should generate the binary file. and when i say make clean, it should delete all the bins and libs.
can u please help me out.
We'll need more information than that to do EVERYTHING you want. Here's a fairly generic makefile:
# Compiler flags, i.e. optimization and include paths
CFLAGS=-O2 -pipe
# C++ compiler flags, including CFLAGS
CXXFLAGS=$(CFLAGS)
# Linker flags, i.e. libraries and lib paths
LDFLAGS=-lm
# All object files
OBJECTS=a.o b.o c.o d.o
# All output target files
TARGETS=ab cd
# The first target should cause all targets to be built
all:$(TARGETS)
# Link ab from a.o and b.o
ab:a.o b.o
$(CXX) a.o b.o $(LDFLAGS) -o $@
# Link cd from c.o and d.o
cd:c.o d.o
$(CXX) c.o d.o $(LDFLAGS) -o $@
# Delete all targets and objects
clean:
rm -f $(TARGETS) $(OBJS)
Wherever I've put eight leading spaces, they're actually tabs and must be tabs for the makefile to work right.
i need to generate a .bin file for my program. how can i do that using makefile ??
Hi.
As Corona688 said, the makefile is a generic one, to get you started.
If the TARGET is to generate a .bin file, then perhaps you should modify the makefile to suit your requirements?
yeah... i am new to creating a makefile... so i dont know what to write in the makefile to create a .bin file. Can anyone please tell me what command to use...
thanks in advance.
Depends on what a .bin file is and what commands are used to create it! I've given you a totally generic makefile to fill in the blanks with; if your build procedure is more complicated or completely different than what I've shown, we're going to need to know what it actually is before we can show how to do it in make.