hii i have c program i need to submit it to the professor bu
hii, i have c program i need to submit it to the professor but he asking me to submit it in a way: (A makefile that can be used to build the executable on a \"normal\" Linux platform using the GNU Compiler Collection) so, how i can do that please really urgent ? please explain to me in steps and thanks for your help ;)
Solution
Makefile is a program building tool used on linux and Unix based systems to manage code compilation. Compiling source files is easy but it can get very diffecult when dealing with thousands of source files. E:g if we have main.cpp, hello.cpp and functions.cpp we simply write
gcc main.cpp hello.cpp functions.cpp -o hello
Since these are only 3 files and we know the sequence of function calls, it was an easy way to compile these 3 files. But when we have hundreds of files makefile comes very handy.
Actually Compiling and executing program includes compilinh source files and then linking object files to make excutable files and the above command excatly does that.
The basic main file has following format
And if we make a makefile for above command that will be like
all:
gcc main.cpp hello.cpp functions.cpp -o hello
This is a simple makefile without any dependencies but sometimes it is useful to use different targets such that if you modify a single file in your project, you don’t have to recompile everything, only what you modified. I that case the makefile will look like this
