GCC commandline option -save-temps

-save-temps

Store the usual "temporary" intermediate files 
permanently; place them in the current directory
and name them based on the source file. Thus, 
compiling `foo.c' with `-c -save-temps' would produce
files `foo.i' and `foo.s', as well as `foo.o'. This
creates a preprocessed `foo.i' output file even though
the compiler now normally uses an integrated preprocessor. 


SESSION 1

$ls
main.c
$gcc -save-temp main.c
gcc: error: unrecognized command line option ‘-save-temp’
$gcc -save-temps main.c
$ls
a.out  main.c  main.i  main.o  main.s
$./a.out

 The Geek Stuff [0]
$ls -l main.o
-rw-r--r-- 1 jeffrin jeffrin 1504 Jan 25 21:18 main.o
$

SESSION 2


$cat hello.c 
#include 

main()
{
  printf("hello");
}
$gcc -save-temps hello.c 
hello.c:3:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
 main()
 ^~~~
$ls
a.out  hello.c  hello.i  hello.o  hello.s
$file he
hello.c  hello.i  hello.o  hello.s  
$file hello.i 
hello.i: C source, ASCII text
$file hello.o 
hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
$./hello.o
bash: ./hello.o: Permission denied
$chmod +x hello.o
$./hello.o
bash: ./hello.o: cannot execute binary file: Exec format error
$./hello.o
bash: ./hello.o: cannot execute binary file: Exec format error
$file hello.s
hello.s: assembler source, ASCII text
$head hello.s
	.file	"hello.c"
	.section	.rodata
.LC0:
	.string	"hello"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
$head hello.i
# 1 "hello.c"
# 1 ""
# 1 ""
# 31 ""
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "" 2
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
$

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s