haziz
haziz

Reputation: 13602

Alias CC to Refer to Clang in a Shell?

Any caveats or gotchas to aliasing cc to refer to Clang within my default shell - zsh (presumably by editing my .zshrc file) while leaving cc aliased to gcc in another shell (bash)?

I find Clang much easier to use mainly because it's warnings and error messages are much more readable and understandable than those of gcc. I will be enrolled in a Unix programming course next semester (purely in C) and am expected to have cleared any gcc -Wall warnings before submission of an assignment.

What I am trying to do is do most of my developing using Clang within my default shell (zsh) using a makefile that refers to the compiler as just cc. Once satisfied I would run it once, as a test, via bash (invoking gcc as the compiler) before submitting. The submitted makefile with cc as the compiler would then invoke gcc for the instructor, making it transparent to them. I am supposed to submit makefiles with each assignment.

I know this just seems like lazyness since I can re-edit the makefile each time, but I am trying to leave less room for error.

Upvotes: 1

Views: 3561

Answers (2)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272667

I won't comment on whether this is fine or not, but there is an easier way. Just use a variable in your Makefile to whatever you want the default to be:

CC=gcc

Then you can override this when you invoke make:

make CC=clang

Upvotes: 0

Just run

  make CC=clang

or

  make CC=gcc

or perhaps

  make CC='gcc -flto -Wall'

(reminder: -flto should be passed at compile and at link time).

Upvotes: 7

Related Questions