views:

108

answers:

1

I've recently upgraded my Ubuntu installation from Jaunty to Karmic. This apparently includes an update of the GNU C compiler, because code that compiled previously no longer does.

Running cc 4.4.1 (Ubuntu 4.4.1-4ubuntu8) now produces the following error, on code that worked fine in the cc 4.3.3 (Ubuntu 4.3.3-5ubuntu4):

$ make
cc -c -MMD -MG -MP -MF lex.d -g -Wall -O -o lex.o lex.c
cc1: error: -MG may only be used with -M or -MM

Adding either the -M or -MM flag resulted in the following message:

[...]
flex -o lex.c lex.l
cc -c -MM -MG -MP -MF lex.d -g -Wall -O -o lex.o lex.c
[...]
cc -g -Wall -O -o translate lex.o grammar.tab.o main.o list.o salloc.o suffixed.o expr.o emit.o optimize.o -lfl
lex.o: file not recognized: File truncated
collect2: ld returned 1 exit status
make: *** [translate] Error 1

I've been told that the various -Mx tell flags make how the various c files depend on .h files. My best fix so far is to tell make explicitly that all .c files depend on all .h files, to make sure everything stays up to date. However, this does induce a lot of unnecessary work at compile time.

My question therefore is: How do I need to adjust the flags for cc to have it handle dependencies automatically again?

A: 

The -MMD switch appears to be the problem. Try changing that to -MM which should allow the -MG switch to work. According to the GCC documentation at http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Preprocessor-Options.html, -MMD is the same as -MM with an impllicit -MF option, and since you've got an output file specified already with -MF, you should be able to use the simpler form.

Ben Combee
Thanks for your suggestion. Unfortunately, replacing the -MMD flag by -MM yields the error "file not recognized: File truncated" :(. I've updated the question with the context of the error, perhaps that information can help?
Evanesco
The problem is that -MM is used in a first pass compilation for generating dependency... usually you then run gcc again to actually make the object file. Using -MM with -o is problematic, as you're writing that dependency info to the .o file and make thinks it's updated. But what you've got in the .o is invalid.
Ben Combee