Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Default Compiler Within Emacs?

I use M-x compile within Emacs to compile my C code which then initiates make -k and allows me to compile the code. I wish to use Clang (or conceivably GCC 4.8 after I install it) as the default compiler. I have cc aliased to clang -Wall -Werror -std=c99 -ggdb -O0 and while this invokes Clang from the command line outside of Emacs, invoking M-x compile from within Emacs still seems to alias cc to GCC version 4.7 which is what I have installed. I wish to tap into the richer and more understandable error and warning messages provided by Clang (and GCC 4.8) but do not wish to create a separate makefile for every short student-level program I am writing, since I am currently going through K&R including solving the exercises.

How do I convince Emacs that M-x compile and make -k should invoke Clang (or GCC 4.8) instead of the older version of GCC?

like image 762
haziz Avatar asked Apr 02 '13 23:04

haziz


1 Answers

This isn't emacs, it's make. It defaults to using the environment variable CC, which in turn defaults to gcc. Just run this before you start emacs (assuming you're using Unix):

$ export CC=clang

Alternatively, use a makefile that specifies CC directly.

like image 117
teppic Avatar answered Oct 30 '22 03:10

teppic