1753288 Members
5384 Online
108792 Solutions
New Discussion юеВ

Re: makefile

 

makefile

I am trying to create a make file.
WhatI need to do is create a makefile that will compile two .cpp files and link them together. Does anyone know how I can create this makefile in the simplest of terms. Thankyou.
3 REPLIES 3
Umapathy S
Honored Contributor

Re: makefile

Brian,
There are numerous resources available in the net.

This book may be old but still holds good to start with makefiles.
http://www.oreilly.com/catalog/make2/

For a headstart tutorial
http://linux.oreillynet.com/pub/a/linux/2002/01/31/make_intro.html

For a complete reference (gnu site is not loading for me right now). Check the manuals section for gmake.

HTH,
Umapathy

Arise Awake and Stop NOT till the goal is Reached!
Steven Gillard_2
Honored Contributor

Re: makefile

The make(1) man page contains the simplest example of what you want:

The following makefile says that pgm depends on two files: a.o and b.o, and that they in turn depend on their corresponding source files (a.c and b.c) and a common file incl.h:

OBJS = a.o b.o

pgm: $(OBJS)
cc $(OBJS) -o pgm

a.o: incl.h a.c
cc -c a.c

b.o: incl.h b.c
cc -c b.c

Just change the dependency lists and commands (remember tabs!)

Regards,
Steve
vasundhara
Frequent Advisor

Re: makefile

Hi,

Here s the sample makefile. Let a.cpp, b.cpp are the cpp files and the binary is z. So, in make file you need to write as below. Make sure that tab is given after ':' you can compile this by using 'make -f '

a.o: CC -c -o a.cpp
b.o: CC -c -o b.cpp
z: a.o b.o

Regards
VJ.