Reputation: 700
Is there any way to reduce the memory used by an executable generated with a command like gcc source_file.c -o result
? I browsed the Internet and also looked in the man page for "gcc" and I think that I should use something related to -c
or -S
. So is gcc -c -S source_file.c -o result
working? (This seems to reduce the space used...is there any other way to reduce even more?)
Thanks, Polb
Upvotes: 0
Views: 1030
Reputation: 106
option -S generate assembler output. Better option is using llvm and generating asembler for multi architecture. Similar http://kripken.github.io/llvm.js/demo.html
llc
here is example https://idea.popcount.org/2013-07-24-ir-is-better-than-assembly/
Upvotes: -3
Reputation: 93162
The standard compiler option on POSIX-like systems to instruct the compiler to optimize is -O
(capital letter O for optimize). Many compilers allow you to optionally specify an optimization level after -O
. Common optimization levels include:
-O0
no optimization at all-O1
basic optimization for speed-O2
all of -O1
plus some advanced optimizations-O3
all of -O2
plus expensive optimizations that aren't usually needed-Os
optimize for size instead of speed (gcc, clang)-Oz
optimize even more for size (clang)-Og
all of -O2
except for optimizations that hinder debugging (gcc)-Ofast
all of -O3
and some numeric optimizations not in conformance with standard C. Use with caution. (gcc)Upvotes: 4