This is in C, am running UNIX through Putty and want to create a Makefile.
So I have a program that is in only one file “recommender.c” and i need to make a makefile that creates an executable file called recommender using the all function. The part i don’t know how to do is that i compile recommender.c using the line gcc recommender.c -std=gnu99
I don’t know how to make sure it does the -std=gun99 part too. please help? 🙂
Note that the file extension must be
.cif it has the extension.cppit will need theCXXFLAGSinstead ofCFLAGSSome explanation:
The make file is dependency based as you can see you can set your variables on top of the make file. Then when the make program is invoked it will search for a
Makefilein the current directory.Since the default action is
allit will search for the all rule.When it found the
allrule it will check which dependencies are needed in this case therecommenderrule / file so it starts searching the rules again and it finds out it needs therecommender.orule / file but it won’t find any, now here is where the magic happens.makeis smart enough to know that an .o (object) file is made from an .c or .cpp (source) file so now it will start searching for the source file in the current directory. This he does by replacing the.owith an.cif it finds the file it will compile it with the gcc compiler if it where to find an.cppfile it will compile it with the g++ compiler.So now we know this we can simply add multiple source files to the project by adding more object file as dependencies.
Now you don’t really need to create an object file first since you compile from one source file you can also remove the
recommender: recommender.orule and make will try to create therecommenderapplication by compilingrecommender.cor.cpp