Sitemap
Shankar Duraisamy

Shankar Duraisamy

Gcc and G++

1 min readSep 19, 2024

--

Gcc

Gcc is a GNU compiler collection that is designed for C and C++. It will also support other languages like Objective-C, Ada, Go, and Fortran with the correct flags or configurations.

By default, “gcc” will compile C code.

Get Shankar Duraisamy’s stories in your inbox

Join Medium for free to get updates from this writer.

compiling C file:

gcc file_name.c -o executable_name

It also compiles C++ code, but you need to explicitly instruct GCC to link the C++ standard library.

gcc file_name.cpp -lstdc++ -o executable_name 

Basic Options:

  • -Wall enables compiler warnings
  • -g is to build non-stripped binaries. Striped binaries will not contain debug information. non-stripped binaries will contain debug information that can be used by the GDB debugger.
  • -I directory to look for the Include or Header files
  • -L directory to look for the library file (.so or .dll files)
  • -l link the library
  • -E only the preprocessing step
  • -S convert the output preprocessing in to Assembly file
  • -ansi sot support only ANSI standards
  • -std=’vesion’ C or C++ language version
  • gcc supports optimization options like O2, O3 to make the binary smaller and faster

G++:

Much like GCC, g++ shares many similarities in function. The key difference, though, lies in its design — g++ is primarily tailored for C++, so it naturally supports C++ by default,. You won’t need to prompt it to link C++ libraries; it’s already set to handle them.

--

--