What are the specific options I would need to build in "release mode" with full optimizations in GCC? If there are more than one option, please list them all. Thanks.
See Question&Answers more detail:osWhat are the specific options I would need to build in "release mode" with full optimizations in GCC? If there are more than one option, please list them all. Thanks.
See Question&Answers more detail:osHere is a part from a Makefile that I use regularly (in this example, it's trying to build a program named foo).
If you run it like $ make BUILD=debug
or $ make debug
then the Debug CFLAGS will be used. These turn off optimization (-O0
) and includes debugging symbols (-g
).
If you omit these flags (by running $ make
without any additional parameters), you'll build the Release CFLAGS version where optimization is turned on (-O2
), debugging symbols stripped (-s
) and assertions disabled (-DNDEBUG
).
As others have suggested, you can experiment with different -O*
settings dependig on your specific needs.
ifeq ($(BUILD),debug)
# "Debug" build - no optimization, and debugging symbols
CFLAGS += -O0 -g
else
# "Release" build - optimization, and no debug symbols
CFLAGS += -O2 -s -DNDEBUG
endif
all: foo
debug:
make "BUILD=debug"
foo: foo.o
# The rest of the makefile comes here...