Makefile Example

From NexusCrossing

Jump to: navigation, search
 #
 # Different header info can go here, but I will keep
 # this simple. 
 #
 
 #
 # This example will create a program named prog,
 # and requires a class named classA
 #
 
 #
 # Two targest, prog and classA.o
 #
 
 prog: prog.cpp classA.h classA.o
         g++ -o prog prog.cpp classA.o
 
 classA.o: classA.cpp classA.h
         g++ -o classA.o -c classA.cpp
 
 #
 # Notice that classA.o uses the -c argument.  This tells
 # g++ to compile ONLY and not link.  This is how you create
 # a module file.  The linker will expect things like a main()
 # function, which is in prog.cpp not classA.cpp 
 #
 # prog goes through linking as well.
 #
 # Remember, MingW will go ahead and tack on the .exe for you,
 # so your make file will be more portable if you leave it out
 # of the output name.  .exe doesn't hurt anything on other
 # platforms, but it looks funky.  :P
 #
 

Remember, the command line comes after a tab, not just spaces.

Personal tools