Currently when I go invoke make I see the following being executed
cc x.c -o x
What I would like to see is the following
cc -ggdb3 -O0 -std=c99 -Wall -Werror x.c -l<lib> -lm -o x
or maybe
clang -ggdb3 -O0 -std=c99 -Wall -Werror x.c -l<lib> -lm -o x
Obviously I could type that every time but I'd prefer when I use make to ultimately use cc with those params.
Is there a make config file somewhere?
1 Answer 1
make
generally uses variables for this; in particular:
CC
specifies the C compiler to use;CFLAGS
specifies C compiler flags to pass the compiler;LDLIBS
specifies libraries to add (although in general you should really write aMakefile
which defines everything your program needs to build, which typically includes libraries).
So you'd run
make CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror" LDLIBS="-lm" x
to get
cc -ggdb3 -O0 -std=c99 -Wall -Werror x.c -lm -o x
and
make CC="clang" CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror" LDLIBS="-lm" x
to get
clang -ggdb3 -O0 -std=c99 -Wall -Werror x.c -lm -o x
You can also set the variables in your environment (which allows defaults to be set in your shell startup scripts):
export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror"
make LDLIBS="-lm" x
Given the absence of a Makefile
in your case, you'll probably find How does this Makefile makes C program without even specifying a compiler? interesting! The GNU Make manual will also come in handy.
-
Brilliant! :) that workedDave Lawrence– Dave Lawrence2017年01月05日 17:23:18 +00:00Commented Jan 5, 2017 at 17:23
-
You're welcome! Be careful if you set defaults though, it can wreak havoc with some builds (so if you download some software, try to build it and it fails, try again without your defaults).Stephen Kitt– Stephen Kitt2017年01月05日 17:27:21 +00:00Commented Jan 5, 2017 at 17:27
-
Good point. While env variables are fine for the moment I intend on putting together my own makefiles. That way I can restrict any changes to where they should be applied. Thanks again.Dave Lawrence– Dave Lawrence2017年01月06日 09:49:42 +00:00Commented Jan 6, 2017 at 9:49
Makefile
contain?make
and it runscc x.c -o x
. (If there is none, that's useful to know too.)