My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at Email :

Thursday, 16 May 2013

How to create a simple make file and compile c++ project in linux?

    Make file is used to compile and link C++ header files, cpp files and associated libraries in Linux platform. 

For more discussions please visit : 


     Look at the bellow example.
     Assume that we have two cpp files that includes 2 header files and one Library file, to write a make file for this C++      project, do the following things.
    "Example1.cpp" associated to "example1.h"
     "Example2.cpp" associated to "exaple2.h" and a lib file called "example2LIB"
  • open a text file and name as "makefile" (Normally no extension)
  • open the file in any text editor
  • Wrtite the bellow expression
      g++  -c  example1.h Example1.cpp exaple2.h Example2.cpp -lexample2LIB -o example
  1. g++ - For calling Linux based c++ compiler
  2. -c - Compile the codes
  3. -l - Link to libraries
  4. -o - Final binary out put
  • Save the file.
  • Open Terminal and move to the project path
  • Type make to compile and link the code , If you got any error in code type vi space cpp or .h file name , 
  • Press i and edit the code correctly press ESC then press :wq to save ["q! to exit without save]
  • If any conflict in object files and intermediate files just add one more line in make file to clean up 
      clean: rm -f <Foldername>/*.o
  • To execute the clean command  type "make clean" in terminal
To avoid re-usage of same keywords or commands in make file creation and make some generality to your make file , just use variables like the following way
Syntax: Variable name=<value>
  • Eg:  CC=gcc
  • CPP=g++
  • To retrive the values from variables use "$" sign
  • Eg : $(CPP) -c example.h example.cpp -o example
  • To display a message to screen when making process use @echo
  • Eg: @echo "Cleaning up directory."
For more discussions please visit : 

For more discussions visit

No comments:

Post a Comment

Note: only a member of this blog may post a comment.