Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Showing results for 
Search instead for 
Did you mean: 



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.
Umapathy S
Honored Contributor

Re: makefile

There are numerous resources available in the net.

This book may be old but still holds good to start with makefiles.

For a headstart tutorial

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


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!)

Frequent Advisor

Re: makefile


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