gcc Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

The GCC command in Linux, which stands for GNU Compiler Collection, is an incredibly powerful tool used primarily for compiling and debugging programs written in C, C++, and other languages. The command gives developers a broad range of control over the compilation process, making it a vital tool in the Linux ecosystem.

Syntax of gcc Command in Linux

The basic syntax of the gcc command in Linux is as follows:

Where:

  • options: These are flags that modify the behavior of the GCC command in Linux.
  • source_files: These are the source code files to be compiled.
  • object_files: These are compiled files that you want to link.
  • -Ldir: This option specifies directories to be searched for libraries.
  • -llibname: This option links the program with a given library.
  • -o outfile: This option defines the name of the output file.
Sharpen Your Fundamentals with Free Learning

Options in gcc Command in Linux

  1. -o: The -o option is used to specify the name of the output file.

    For example -

    This will compile 'program.c' into an executable named 'program'.

  2. -Wall: The -Wall option enables all compiler's warning messages.

    For example -

    This will compile 'program.c' and display all warning messages.

  3. -g: The -g option enables debugging information.

    For example -

    This will compile 'program.c' with debugging information which is useful for gdb debugger.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Simple program compilation:

    Output:

    Explanation: This will compile 'program.c' into an executable named 'a.out'.

  • Compiling program with warnings:

    Output:

    Explanation: This will compile 'program.c' into an executable named 'a.out', showing all warning messages.

Tips

  • Use the -Wall flag to catch common errors and warnings during the development process.

  • To compile programs written in C++, use g++ instead of gcc.

  • Use the -g flag to generate debugging information when dealing with complex code that might require debugging.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of gcc Command in Linux

  • Compiling multiple source files:

    Output:

    Explanation: This command compiles 'main.c', 'program1.c', and 'program2.c' together into an executable named 'a.out'.

  • Linking against a library:

    Output:

    Explanation: This command compiles 'program.c', links the resulting object file with 'libmylib.a' or 'libmylib.so' located in '/opt/lib', and produces an executable named 'program'.

  • Compiling with optimization:

    Output:

    Explanation: This command compiles 'program.c' into an executable named 'a.out' with level 2 optimization.

Conclusion

  • GCC command in Linux is a powerful tool for compiling and debugging programs.

  • Various options of gcc command allow fine control over the compilation process.

  • GCC supports multiple programming languages and allows linking against libraries.