|
|
g++
Released by the Free Software Foundation, g++ is a *nix-based C++ compiler usually operated via the command line. It often comes distributed with a *nix installation, so if you are running Unix or a Linux variant you likely have it on your system. You can invoke g++ on a source code file simply by typing
g++ filename
The default executable output of g++ is "a.out". It is also possible to specify a name for the executable file at the command line by using the syntax
-o outputfile
, as shown in the following example:
g++ filename -o outputfile
Catching Problems Early
In order to compile with all warnings enabled and to produce standards-compatible C++ code, I recommend using the flags
-Wall -ansi
You can read more on the value of compiler warnings.
If you want to have the compiler treat warnings as errors--meaning you don't even get an executable, you can use the -Werror flag. This will make sure you don't miss an error.
GDB Ready Code
If you want to prepare your executable for use by GDB, include the -g flag.
g++ filename -g -o outputfile
This will enable GDB to give you detailed debugging information by including extra code in the executable file to allow GDB to find variable names and list the source code.
Find Out More
If you are using a *nix system, you can also check out the other g++ commandline options by typing
man g++
Creating shared libraries
If you want to learn how to create a shared library on Linux with GCC, check out the article how to create a shared library on Linux using GCC
|
|
|
|