You are on page 1of 7

INTRODUCTION

Linux
• Clone of Unix operating system
• Its kernel written by Linus Trovalds with team of
programmers from around the world on Internet.
• Its free of cost and has all features of any modern OS.
• Kernel of Linux is available in source code form,
anybody is free to change it to suit his requirement
with a precondition that the changed kernel can be
distributed only in the source code forsome popular
distributions are RedHat, Mandrake, SUSE, Ubundu
etc.
Advantages of running C in Linux
• The most important among it is full word length utilization.
• Portability -- UNIX, or a variety of UNIX, is available on many machines. Programs
written in standard UNIX and C should run on any of them with little difficulty.
• Multiuser / Multitasking -- Many programs can share machines processing power.
• File handling -- hierarchical file system with many file handling routines.
• Shell Programming -- UNIX provides a powerful command interpreter that
understands over 200 commands and can also run UNIX and user-defined
programs.
• Pipe -- where the output of one program can be made the input of another. This
can done from command line or within a C program.
• UNIX utilities -- there are over 200 utilities to accomplish many routines without
writing new programs. e.g. make, grep, diff, awk, more ....
• System calls -- UNIX has about 60 system calls that are at the heart of the
operating system or the kernel of UNIX. The calls are actually written in C. Basic
I/0, system clock access, open() are examples.
• Library functions -- additions to the operating system.

12/3/2019
What is gcc?
• gcc – GNU(GNU stands for “GNU's Not Unix”. ) compiler
collection
– stands for GNU C/C++ Compiler
– a popular console-based compiler for UNIX platforms and
others; can cross-compile code for various architectures
– gcc to compile C programs; g++ for C++
– can actually work with also ADA, Java, and a couple other
languages
– gcc performs all of these:
• preprocessing,
• compilation,
• assembly, and
• linking
• As always: there is man gcc
C/C++ Program Compilation
• Creating the program
• Create a file containing the complete program.
You can use any ordinary editor with which
you are familiar to create the file. One such
editor is textedit available on most UNIX
systems.
• The filename must by convention end ``.c''
(full stop, lower case c), e.g. myprog.c or
progtest.c. The contents must obey C syntax.
Compilation
• There are many C compilers around. The cc being the default Sun compiler. The GNU C
compiler gcc is popular and available for many platforms. PC users may also be familiar with
the Borland bcc compiler.

• There are also equivalent C++ compilers which are usually denoted by CC (note upper case
CC. For example Sun provides CC and GNU GCC. The GNU compiler is also denoted by g++

• To Compile your program simply invoke the command cc. The command must be followed by
the name of the (C) program you wish to compile. A number of compiler options can be
specified also.

• Thus, the basic compilation command is:


• cc program.c
• where program.c is the name of the file.

• If there are obvious errors in your program (such as mistypings, misspelling one of the key
words or omitting a semi-colon), the compiler will detect and report them.

• When the compiler has successfully digested your program, the compiled version, or
executable, is left in a file called a.out or if the compiler option -o is used : the file listed after
the -o.
• It is more convenient to use a -o and filename in the compilation as in
• cc -o program program.c
• which puts the compiled program into the file program (or any file you name following the "-
o" argument) instead of putting it in the file a.out .
Running the program
• To run an executable in UNIX, you simply type
the name of the file containing it, in this case
program (or ./a.out)
• This executes your program, printing any
results to the screen. At this stage there may
be run-time errors, such as division by zero, or
it may become evident that the program has
produced incorrect output.
• If so, you must return to edit your program
source, and recompile it, and run it again.

You might also like