• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

g++: Compiles C++ source files

by admin

The g++ command is a widely used compiler for the C++ programming language. It is a part of the GCC (GNU Compiler Collection), which is a suite of compilers developed by the Free Software Foundation (FSF). The GCC is a powerful and popular compiler toolchain that supports multiple programming languages, including C, C++, Ada, Fortran, and more.

When you invoke the g++ command, it acts as a front-end to the GCC and handles the compilation process specifically for C++ source code. It takes the C++ source files (files with a .cpp extension) as input and produces executable machine code that can be run on the target system.

The g++ command provides a range of options and flags that allow you to customize the compilation process. For example, you can specify optimization levels, include directories, libraries, enable warnings, and much more. These options help you control how the code is compiled and optimize the resulting executable for performance, size, or debugging purposes.

In addition to compiling C++ source files, g++ can also link object files and libraries to create the final executable. It handles the entire build process, including preprocessing, compiling, assembling, and linking, making it a convenient tool for building C++ applications.

g++ Command Examples

1. Compile a source code file into an executable binary:

# g++ /path/to/source.cpp -o /path/to/output_executable

2. Display common warnings:

# g++ path/to/source.cpp -Wall -o /path/to/output_executable

3. Choose a language standard to compile for (C++98/C++11/C++14/C++17):

# g++ /path/to/source.cpp -std=[c++98|c++11|c++14|c++17] -o /path/to/output_executable

4. Include libraries located at a different path than the source file:

# g++ path/to/source.cpp -o /path/to/output_executable -I path/to/header -L path/to/library -llibrary_name

5. Compile and link multiple source code files into an executable binary:

# g++ -c /path/to/source_1.cpp /path/to/source_2.cpp ... && g++ -o /path/to/output_executable path/to/source_1.o /path/to/source_2.o ...

6. Display version:

# g++ --version

Summary

Overall, g++ is a versatile and widely used compiler that plays a crucial role in the development of C++ applications. Its integration with the GCC provides access to a comprehensive set of tools and libraries, making it a popular choice among C++ developers.

Filed Under: Linux

Some more articles you might also be interested in …

  1. cargo clippy: A collection of lints to catch common mistakes and improve your Rust code
  2. How to uninstall scons package from Ubuntu
  3. locate Command Examples in Linux
  4. e4defrag: command not found
  5. Linux OS Service ‘yppasswdd’
  6. top Command Examples in Linux
  7. setsid: command not found
  8. Understanding the Network interface configuration file /etc/sysconfig/network-scripts/ifcfg-eth#
  9. How to increase swap space on Linux
  10. less Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright