How do I set the C compiler in a Makefile?

How do you set your C compiler in a Makefile? You might write:

a.out: main.c
	clang main.c

clang is your C compiler. Alternatively, you can write:

a.out: main.c
	cc main.c

This does the same thing, because cc is a symbolic link to clang (on my machine):

% ls -l `which cc`
lrwxr-xr-x  1 root  wheel  5  7 Oct 13:11 /usr/bin/cc -> clang

You can also write:

a.out: main.c
	$(CC) main.c

This again does the same thing, because $(CC) in a Makefile expands to cc. CC is a predefined variable. The point of this is that you may want to redefine CC.


I wrote this because I felt like it. This post is my own, and not associated with my employer.

Jim. Public speaking. Friends. Vidrio.