2

I am trying to compile a piece of code that was previously compiled with gfortran in ifort instead. The old compile line has a -xf95-cpp-input option in it that doesn't make sense to me.

Looking in the GCC docs, it seems like the -x option tells the compiler to ignore the file extension of the source code file, and parse it explicitly with the language you tell it to. So for example, I could run gfortran -xf77 myfunkycode.lulwut and it will parse my .lulwut file as an f77 file.

This makes sense, but then what does f95-cpp-input or c++-cpp-output mean? What do 'input' and 'output' even mean in this context? I'm guessing "input" is the source code? "Output" is the object file? According to the docs, -x is just for choosing the "language of the input file," why is 'output' in the language list at all?

Frank
  • 544
  • 2
  • 14

1 Answers1

4

f95-cpp-input

Compile the source file as f95 file with cpp preprocessor.

c++-cpp-output

Compile the source file as C++ file without cpp preprocessor.

What do 'input' and 'output' even mean in this context?

Just a convention I guess.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • 1
    So generally, "lang1-lang2-input" means "lang1 with lang2 preprocessor" and "lang1-lang2-output" means "lang1 without lang2 preprocessor"? For "c++-cpp-output" what is it doing for the preprocessor, just using C? Or no preprocessor? – Frank Nov 19 '20 at 19:35
  • 1
    For that matter, what's the difference between "c++-cpp-output" and "cpp-output"? – Frank Nov 19 '20 at 19:37
  • 1
    My guess is `cpp-output` is C source file without cpp. `c++-cpp-output` is a C++ source file without cpp. Seems to check out - `printf "%s\n" "#define a main" "int a() {}" | gcc -x cpp-output -` fails with undefined main - `#` are comments. – KamilCuk Nov 19 '20 at 19:49
  • 1
    `So generally,` No idea, it makes no sense to me, I would just learn the options by heart. `For "c++-cpp-output" what is it doing for the preprocessor, just using C?` It compiles the file as C++ without running the preprocessor. There is no C involved. `Or no preprocessor?` Literally, yes. – KamilCuk Nov 19 '20 at 19:52
  • when you say it as "without cpp preprocessor" the first place my mind goes is "well, I guess you could use a different preprocessor" since you didn't say "without any preprocessing." Compiling without any preprocessor step just strikes me as bizarre and alien. – Frank Nov 19 '20 at 19:56
  • `Compiling without any preprocessor step just strikes me as bizarre and alien` Really? Compiling is famously done in 4 stages, source file -> preprocessing (cpp) -> compiling (gcc) -> machine code (assembler, also gcc) -> linker (ld) -> output. It's just without the cpp step. – KamilCuk Nov 19 '20 at 20:07
  • Right, 4 stages not three. I can't imagine why you'd want to skip the preprocessing stage. – Frank Nov 20 '20 at 14:32
  • @Frank - it's necessary when you have a build process that looks like: `gcc -E` (run the preprocessor on a file)-> then run some tool or filter that changes the code further -> `gcc -x cpp-output`. Basically it means "this file has already been through the preprocessor once, so just run the compiler and later stages on it." – librik Jun 24 '23 at 21:15