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 just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

With Vidrio

With generic competitor

More by Jim

Tagged . All content copyright James Fisher 2016. This post is not associated with my employer. Found an error? Edit this page.