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.

Tagged #make, #c, #programming.

Similar posts

More by Jim

👋 I'm Jim, a full-stack product engineer. Want to build an amazing product and a profitable business? Read more about me or Get in touch!

This page copyright James Fisher 2016. Content is not associated with my employer. Found an error? Edit this page.