Someone recently mentioned the target .c.o
in Makefiles for cross compatability, but I fail to understand its purpose. Can anyone clarify?
Asked
Active
Viewed 2.4k times
41

Carl Norum
- 219,201
- 40
- 422
- 469

chacham15
- 13,719
- 26
- 104
- 207
2 Answers
48
It's an old-fashioned suffix rule. The more up-to-date way to do it is to use a pattern rule:
%.o : %.c

Carl Norum
- 219,201
- 40
- 422
- 469
2
It's a canned rule for translating .c
files, i.e. C modules, to .o
object files. It exists so you don't have to write this rule yourself and is parameterized by Make variables such as CC
(the C compiler to use), CFLAGS
(compiler flags), etc.
So, if you use this implicit rule to compile C modules and don't tinker with any Make variables, then the person building your code can specify a compiler and flags on the command line without editing the Makefile.

Fred Foo
- 355,277
- 75
- 744
- 836
-
2but you can do that with the pattern rule as well: `make "CC = gcc"` for example – chacham15 Feb 10 '12 at 19:20
-
1@chacham15: that's right. `.c.o` is the older way of doing this. – Fred Foo Feb 10 '12 at 19:21