11.27.2012

Make and Makefiles

Make and Makefiles



The compiler is one of the most important parts of the C programming environment. I can write Java until I'm blue in the fingers without ever having to actually USE the java compiler. Sure, it is being used in the background all the time with eclipse, but IDEs make me stupid. I don't actually learn what is happening when I click the pretty little 'run' button, I just see the output.

GNU Make is a tool that you will use constantly. It is used to generate executables and other non-source files from your source code. It does this using rules you set up in a makefile. Using the makefile, you'll be able to build and install the program you have written. So lets take a look at make files.

To set up a fairly simple example of a make file we can use the hello.c file for our C 'program.' What better example to use than Hello World.

I also included a very simple Makefile along with hello.c.
You should be able to use the commands
make hello
to build the executeable
make clean
to clean the files up

When you run make clean, it actually runs the 'clean:' target of the Makefile, which  removes the 'hello' executable.

Makefile

hello.c

That's a very simple introduction on how to make a basic Makefile. Soon, I'll write another blog post describing some of the more in depth pieces of Makefiles.

No comments:

Post a Comment