For a GCC or Clang command, there is typically one primary outputfile, specified by -o
or the default (a.out
ora.exe
). There can also be temporary files and auxiliaryfiles.
We can specify the primary output file with the -o
option. When unspecified, a default output file name is inferred fromthe input files and the final phase. When the final phase is linking,the default output file name is a.out
ora.exe
.
1 | gcc -S d/a.c # a.s |
For compilation and linking in one command, the relocatable objectfiles are temporary files.
For GCC, when generating a relocatable object file, it needs togenerate a temporary assembly file, then feeds it to GNU assembler.
We can set the temporary directory with one of the environmentvariables TMPDIR
, TMP
, and TEMP
.When none is specified, compilers have a fallback, /tmp
on*NIX systems.
Beside primary output files and temporary output files, we have athird output file type called auxiliary output files. Some options suchas -ftest-coverage
and -gsplit-dwarf
cause the compiler to generate auxiliary output files.
For compilation without linking (-c
, -S
,etc), the auxiliary output file names are derived from the primaryoutput file name.
For compilation and linking in one command, the primary output filename affects the auxiliary output file names.
1 | gcc -c -g -gsplit-dwarf d/a.c d/b.c # a.o b.o a.dwo b.dwo |
GCC provides some optionsthat are primarily of interest to GCC developers. These dump outputfiles are treated the same way as auxiliary output files.
-dumpdir
and -dumpbase
are provided tocontrol the auxiliary output file names. The officialdocumentation may be difficult to follow. Let's see someexamples.
1 | gcc -g -gsplit-dwarf -dumpdir f d/a.c -c # fa.dwo |
In the absence of -dumpdir
, -dumpbase
appends a dash, which makes it inconvenient.
I suggest that you only use -dumpdir
.
I have a patch to support -dumpdir
in Clang: https://reviews.llvm.org/D149193.
-save-temps
-save-temps
and -save-temps={cwd,obj}
generate intermediatefiles.
In the absence of -dumpdir
/-dumpbase
,-save-temps
is like an alias for-save-temps=cwd
and stores intermediate files in thecurrent directory. -save-temps=obj
stores intermediatefiles in the directory of the output file specified by-o
.
When -dumpdir
is specified, there is complex interactionbetween -dumpdir
and-save-temps
/-save-temps={cwd,obj}
. For Clang,I think we should make -dumpdir
and-save-temps
/-save-temps={cwd,obj}
orthogonal.
1 | # The last of -dumpdir and -save-temps wins. |
Clang supports a few options (e.g. -ftime-trace
) togenerate other auxiliary output files. I plan to change their file namesto be controlled by -dumpdir
.