www.delorie.com/djgpp/faq/dev-probs/extensions.html   search  
I type "GCC PROG.CC" and it complains that it can't recognize PROG.CC's file format. How come a C++ compiler doesn't recognize a C++ source??

I type "GCC PROG.C" to compile a C program which I already remember to pass compilation without a single warning, and suddenly it gives all kinds of strange error messages and unresolved externals.

That's because you typed your source file extension in upper case. gcc is not case insensitive about filenames like DOS is, and it uses the file's extension to determine how to compile a file. Valid extensions are:

.cc, .C, .cxx, .cpp
C++ source (passed through cpp)
.c
C source that must be passed through cpp first
.i
raw C source (no cpp pass)
.ii
raw C++ source (not to be preprocessed)
.m
Objective-C source.
.S
assembler that must be passed through cpp first
.s
raw assembler source (no cpp pass)
any other file is passed to the linker, under the assumption that it's an object file.

In the examples above, PROG.C is taken as C++ program, not a C one, and PROG.CC is passed to the linker as if it were an object file.

You can override the default rules gcc uses to decide how each input file should be treated, with the help of ``-x LANGUAGE'' switch. For instance, the command

  gcc -x c++ prog.c
compiles prog.c as a C++ source. See gcc docs for more info on -x options.


  prev   next     webmaster   donations   bookstore     delorie software   privacy  
  Copyright 1995   by DJ Delorie     Updated Feb 1995