C

Some Handy GCC Options

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project.

When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The “overall options” allow you to stop this process at an intermediate stage.

This post is about some handy GCC command line options, that you may find useful.

-E

Look at the code after preprocessor. (The #defines relacements? 🙂 )

-Werror

This makes all warnings into hard errors. Source code which triggers warnings will be rejected.

-fsyntax-only

This checks the code for syntax errors, but don’t do anything beyond that.

-Werror=

This makes a specified warning into an error.

-Wfatal-errors

This option causes the compiler to abort compilation on the first error occurred rather than trying to keep going and printing further error messages.

-Wall

This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.

-Wextra

This enables some extra warning flags that are not enabled by -Wall.

-Wnonnull

This warns about passing a null pointer for arguments marked as requiring a non-null value by the nonnull function attribute.

-fsanitize=undefined

This enables UndefinedBehaviorSanitizer, a fast undefined behavior detector.

-finline-functions

This considers all functions for inlining, even if they are not declared inline. The compiler heuristically decides which functions are worth integrating in this way.

-undef

This is to, not predefine any system-specific or GCC-specific macros. The standard predefined macros remain defined.

-funsigned-char

Through this option, the char type is treated as unsigned type.

-v

This is to provide verbose information on all the steps gcc takes while compiling a source file.

-fshort-double

This is to use the same size for double and float.

I’ll add as I use more.

A big list is here.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s