Makefile

WHAT IS MAKEFILE?

As you begin to work on larger projects you will find it necessary to have a means to organize the compilation of your source code. Having to compile multiple files from the command line can become a tedious and time consuming task. The GNU Make program will make this process much easier to deal with. If you have ever compiled or installed software on your linux system the chances are you have run ‘make’ to compile it for you.
When you run ‘make’ it looks for a file named ‘Makefile’, this file holds a set of rules for compiling the project. The files you are compiling are automatically examined to detect changes, if a change has been made or a certain file is not present it will be compiled, otherwise it ll be left unchanged. This is very useful when you start making very small changes to a large program, you only need to recompile the files you made changes too and then link them together.
This  will go over the basic steps for creating your own Makefiles and getting a handle on compiling your multifile projects.

HOW TO MAKE MAKEFILE AND HOW TO RUN?

I saved the above program with the name main.cpp

to compile this you have to create a “makefile” in the same folder and name it as “makefile”(without quotes).

and paste the below code in that makefile.

CXX := g++

all: main

clean:
      $(EXECUTABLE) *.o

 

after all this open terminal,and type the path where your folder containing the
program and makefile is placed
and enter

make


and then enter

./main

you will get the require output.

Leave a comment

Sandeep Ghai

looking forward for the best happenings

surbhikapoor

A great WordPress.com site

my net house

WAHEGURU....!

Design a site like this with WordPress.com
Get started