GCC COMAND

 GCC

-----------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------


What is the meaning about GCC?:

GCC is abbreviated as GNU Complier Collection. GCC can compile C, C++, Ada and many more programming languages which are understandable by the system.

GCC is a short of GNU Compiler Collection, a C compiler for Linux.

---------------------------------------

Basic GCC Syntax:

gcc [options] [source_file] [object_files] [-o output_file]

  • ----------------------------------------
  • ----------------------------------------

Option:

  • To check the default version of gcc compiler in your system, you can use the command as –version in your Linux command prompt.  
gcc –version

  • Compiles source files to object files without linking to any other object files.
Gcc –c


  • Includes the directories of header files
gcc –Idir
  • link the code with the library files
gcc –llib
  • Build the output generated to output file
gcc -o output file
  • Disables all warning messages during the compilation.
gcc –w
  • enables all warning messages during the compilation
gcc –Wall
  • Enables extra warning messages during the compilation.
gcc –Wextra
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

To Execute a C program, we need to follow three steps. They are:

  1. Write: C Program for which you want to compile in Linux environment.
Create a C program to print “Hello World” in Linux by following the below steps. Make sure you save the C program with .c as its extension. The below steps are to create a .c file and write the code in it. Save before you close the file.
----------------------------------------------------------------------
-------------------------------------------------------------------

        2. Compile: Program to check if any error exists or not.
Now below are the options to compile a simple C program using GCC in Linux. You can use the options as per your requirement and build your program to get desired output.

  • The basic syntax to compile a C code is: To compile a C Code, use the below syntax. This syntax is used without any options.
gcc main.c
  • When you compile the above code, you will get the output with the filename as a.out. The default output after compiling the C Program is resulted in”a.exe” or “a.out” format.
  • We can also specify explicitly mention the output file name by using –o as an option.
gcc main.c –o output
  • To see the warnings while we compile a C program: we need to use an option –wall while compiling the C Program as below:
gcc –wall main.c –o output

Once we set –wall option, we can see the warnings that can occur in our code. Here our code will give uninitialized warning for the variable “i”.
  • To get preprocessed output with –E option: the output will be produced on stdout to redirect our result in other file. Here output.i would contain the preprocessed result.
gcc –E main.c > output.i
  • To get intermediate files using –save-temps: We can store all the intermediate files that are generated during the compilation in the same directory from where we do the compilation.
gcc –save-temps main.c
  • To see the error while compiling the C ProgramTo see the error during the compilation of C Program, we can use the option –W. This is one of the best practices to use to avoid errors.
gcc main.c –Werror –o output
  • To debug C Program in Linux: To debug C Program in Linux during compilation can be done by using –ggdb.
gcc –ggdb main.c –wall –o output
  • Verbose option is to see the complete description used in Linux during the compilation. The command –v is used as below:
gcc –v  main.c –o output

---------------------------------------------------------------------------------------
--------------------------------------------------------------------------
        3. Run: Program to see the output in Linux environment.
  • The final step is to run the C program in Linux OS by using the below syntax:
./program_name
./output

---------------------------------------------------------------------
---------------------------------------------------------------------

for more info 
  • https://www.geeksforgeeks.org/gcc-command-in-linux-with-examples/
  • https://web.mit.edu/rhel-doc/3/rhel-gcc-en-3/invoking-gcc.html
  • https://www.rapidtables.com/code/linux/gcc.html
--------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------
------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------

REFERENCIAS:

geeksforgeeks        https://www.geeksforgeeks.org/gcc-command-in-linux-with-examples/

rapidtables.com    https://www.rapidtables.com/code/linux/gcc.html

educba.com           https://www.educba.com/gcc-command-in-linux/


Comentarios