René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
gcc options | ||
-M
Instead of outputting the result of preprocessing, output a rule suitable
for make describing the dependencies of the main source file. The
preprocessor outputs one make rule containing the object file name for that
source file, a colon, and the names of all the included files, including
those coming from -include or -imacros command line options.
Consider the following files:
opt_m_A.h:
class A { public: A(); };
opt_m_A.cpp:
#include "opt_m_A.h" A::A() { }
opt_m_B.h:
#include "opt_m_A.h" class B : public A { public: B(); };
opt_m_B.cpp:
#include "opt_m_B.h" B::B() : A() { }
opt_m_main.cpp:
#include "opt_m_B.h" int main() { B b; return 0; }
Now, invoking gcc with
g++ -M opt_m_*.cpp
results in:
opt_m_A.o: opt_m_A.cpp opt_m_A.h opt_m_B.o: opt_m_B.cpp opt_m_B.h opt_m_A.h opt_m_main.o: opt_m_main.cpp opt_m_B.h opt_m_A.h -Wl,option
Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. That is, the commas are replaced with spaces.
-static-shared
This is actually an option to the linker, not the compiler.
-Idir
Appends dir to the list of directories in which the preprocesser searches for include files.
-nostdlib
When gcc is used to invoke the linker, gcc adds several command-line
arguments, one of which is -lc. This causes the linker to search in the system-supplied
standard C library for functions not supplied by your own source files. This option is so
frequently needed that gcc passes it to the linker (along with all the command-line arguments
we supplied) unless the -nostdlib option is used to force gcc not to.
All options passed are shown with the -v option.
-o
Names the output file.
-Ldir
Adds dir to the directories in which the linker searches for libraries. Unless otherwise instructed, gcc uses shared libraries in preference to static
libraries.
-lname
Links against libname.so (shared library) if found, otherwise against libname.a (static library). If both are not found, an error
is emitted.
Note, a library must begin with lib and end in .a (.so?). However, neither lib nor .a must be specified.
Use -L to add search paths for libraries.
-c
Compiles the source file(s), but does not link it/them.
-v
Show compiler version.
-E
Preprocess source file only.
Comments will be discared unless -C is also specified.
Creates
#line directives unless -P is also specified.
-C
Keep comments (used together with -E.
-P
If specified, does not generate
#line commands.
-pipe
Doesn't create temporary files for the steps involved in compiling and linking a program. Instead, passes the output of one step through a pipe to the next step.
-ansi
Non-ansi features (except some Turbo C idioms) will not be compiled. In order to force full ansi conformance, -pedantic must be specified.
-pedantic-S
Compiles and stops. Output is assembler code (suffix .S).
-w
Suppres warning messages.
-W
Print extra warning messages.
-Wimplicit
-Wunused
Does not detected variables that invoke a constructor ?
#include <string> int main() { std::string i; int b; return b; } -Wall
The combination of
-Wtraditional-Wundef-Wshadow-Wid-clash-LEN-Wlarger-than-LEN-Wpointer-arith-Wbad-function-cast-Wcast-qual-Wcast-align-Wwrite-strings-Wconversion-Wsign-compare-Waggregate-return-Wstrict-prototypes-Wmissing-prototypes-Wmissing-declarations-Wredundant-decls-Wnested-externs-Winline-Wold-style-cast-Woverloaded-virtual-Wsynth
C++ only
-Wlong-long-Werror
Turn all warnings into errors.
-f-fpic
Position independant code, needed for shared libraries.
-fPIC
Position independant code, needed for shared libraries.
I am a bit in the dark what exactly the difference between -fpic and -fPIC is. It seems that
-fPIC works always while -fpic produces smaller object files.
-fomit-frame-pointer
This option should not be used when building shared libraries.
-g
Creates debugging information for the gnu debugger (gdb).
-ggdb
Adds additional debugging information suitable for the gnu debugger (gdb).
-On
Optimizes generated code. n is a number, the higher the number, the better the optimization.
-x
Override the file's extension.
For example, the following command treats a.cpp as a c file although its extension indicates a c++ file:
gcc -x c
The following languages are recognized:
-Weffc++
Checks for violations of a few of the guidelines in Scott Meyers' Effective C++ book.
|