2

Is it possible to produce both the object file and the source file in once command with gcc/g++/clang/clang++ ? How?

I need to pass a lot of other options, so I would like to avoid duplicating them in 2 separate commands:

gcc -S test.cc # produce assembly
gcc -c test.cc # produce object file
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158

1 Answers1

1

You can give the -save-temps option to gcc: it will leave all the temporary files (including the .s files) in the current directory (works also with clang):

gcc -c --save-temps test.cc

or use the -Wa,-aln=test.s option:

gcc -c -Wa,-aln=test.s test.c

From gcc documentation:

-Wa,option

Pass option as an option to the assembler. If option contains commas, it is split into multiple options at the commas.

From as documentation:

-a[cdghlmns] Turn on listings, in any of a variety of ways:

  • -al include assembly
  • -an omit forms processing

[...]

You may combine these options; for example, use -aln for assembly listing without forms processing.

Clang has an integrated assembler that should be switched off (How to switch off LLVM's integrated assembler?):

clang++ -c -no-integrated-as -Wa,-aln=test.s test.c
Community
  • 1
  • 1
manlio
  • 18,345
  • 14
  • 76
  • 126
  • 1
    It seems that `clang -c --save-temps test.cc` uses a different assembler than just `clang -S` or `clang -c`. And that assembler gives an error message on a feature being added to clang... Neither `clang -S` nor `clang -c` produce that error. So I don't know whether my modification is wrong or some more tweaks to the environment are needed. I'm on Windows, cross-compiling to ARM-Linux. – Serge Rogatch Sep 07 '16 at 17:21