Learn more about Israeli war crimes in Gaza, funded by the USA, Germany, the UK and others.

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

Want to build a fantastic product using LLMs? I work at Granola where we're building the future IDE for knowledge work. Come and work with us! Read more or get in touch!

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