SlideShare a Scribd company logo
Programming in the Linux
Environment

ISO C and POSIX Standards
The Development tools
Using GCC
Creating and Using Libraries
Dynamic modules
Debugging with GDB
What are ISO C and POSIX
Standards and Why should we
     care about them ?
The Development tools available in
     the Linux Environment
 – Programming Languages Available
      ✔ C

      ✔ C++

      ✔ Java

      ✔ Python

      ✔ C# (CLR comes from the Mono Project)

      ✔ Perl

      ✔ Tcl/tk

      ✔ Vala

      ✔ Lua

      ✔ Ada

      ✔ PHP

      ✔ Ruby

      ✔ Haskell, Pascal, Fortran, Lisp,
The Development tools available
   in the Linux Environment
  – Tools for C Programming
       • GCC: GNU Compilers Collection
       • GDB: GNU Debugger
       • Emacs/Vi: The code editors
Using GCC
– Writing A “Hello World” Program
– Compiling and Running the program

 gcc -o helloworld helloworld.c

 ./helloworld
Using GCC
– Some Essential features of GCC
    • Including Additional Header Files

 gcc -I/home/abhinav/code/include
  include-test.c -o include-test

 ./include-test
Using GCC
– Some Essential features of GCC
    • Linking Libraries
    • Debugging symbols
    • Creating libraries
Creating and Using Libraries
  – Libraries are a collection of functions
  – libm, libpthread, libdbm, libc

    Types of Libraries:
  – Static Libraries: .a extension
  – Dynamic Libraries: .so extension
Creating and Using Libraries
 – Making object files:

          gcc -I./include -c new-helloworld.c print.c

 – Linking Object files

        • Gcc -o new-helloworld new-helloworld.o
           print.o

   -c : tells the compiler to only compile the
     file, but not to link them
   -o: to specify the name of the output file.
Creating and Using Libraries
  – Creating Static Library:

         • gcc    -o *.c

         • ar cr libcalc.a *.o

  – Linking against the static library:

    gcc -I./include -o calc-test calc-test.c -L.
      -lcalc
Creating and Using Libraries
  – Creating Shared Library:

         • gcc    -c -fPIC *.c

         • gcc -shared -fPIC -o libcalc.so *.o

  – Linking against the shared library:

    (Same as linking against a static library)

    gcc -I./include -o calc-test calc-test.c -L.
      -lcalc
Debugging with GDB
– Generating debugging symbols:
      • gcc -g -o

  Starting the debugger:
        • gdb <program name>

  Some common commands:
     • b line-number or function name: sets the break point
     • next : step over
     • step: step in
     • p <variable name> : prints the value of the variable
     • where: prints the stack trace
     • up: moves you up in the stack
Dynamically Loading Modules


 – Concept of Plugins/modules which are loaded by the program
     at run tim
 – No dynamic or statical linking of libraries

   void *handle = dlopen(“libcalc.so”, RTLD_LAZY);
   void (*test) () = dlsym(handle, “add”);
   (*test) ();
   dlclose (handle);
Some other productivity tools

        Diff: What are the changes made in the file
               Patch: merging the changes
  Version Control tools: Git, Bazaar, mercurial, SVN, CVS
Thank You
       --Abhinav Upadhyay
          Twitter: iamabhi9
Irc.freenode.net: abhinav-

More Related Content

ODP
Debug JNI code with ndk-gdb and eclipse GUI
PDF
Kubernetes on CRI-O
PPTX
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
PPTX
Kubernetes CRI containerd integration by Lantao Liu (Google)
PDF
containerd and CRI
PDF
"Building, deploying and running production code at Dropbox" Васильев Леонид,...
PPTX
Front end development
PDF
OpenCms Days 2012 - Developing OpenCms with Gradle
Debug JNI code with ndk-gdb and eclipse GUI
Kubernetes on CRI-O
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Kubernetes CRI containerd integration by Lantao Liu (Google)
containerd and CRI
"Building, deploying and running production code at Dropbox" Васильев Леонид,...
Front end development
OpenCms Days 2012 - Developing OpenCms with Gradle

What's hot (17)

PDF
OSDC 2017 - Dr. Udo Seidel - VMwares (open source) Way of Container
PDF
CRI, OCI, and CRI-O
PPTX
PDF
[Szjug] Docker. Does it matter for java developer?
PDF
OpenCms Days 2013 - Gradle based OpenCms build automated setup
PPTX
Containers: Anti Pattern
PPTX
PDF
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
PPTX
Lando - AddWeb Solution
PPTX
runC – Open Container Initiative
PDF
BKK16-407 AOSP Toolchain Evolution and experimental languages on AOSP
PDF
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
PPTX
LLVM Compiler
PDF
Containers and Orchestration approaches
PDF
Bucketbench: Benchmarking Container Runtime Performance
PDF
Overview of the Open Source Vulkan Driver for Raspberry Pi 4
OSDC 2017 - Dr. Udo Seidel - VMwares (open source) Way of Container
CRI, OCI, and CRI-O
[Szjug] Docker. Does it matter for java developer?
OpenCms Days 2013 - Gradle based OpenCms build automated setup
Containers: Anti Pattern
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
Lando - AddWeb Solution
runC – Open Container Initiative
BKK16-407 AOSP Toolchain Evolution and experimental languages on AOSP
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
LLVM Compiler
Containers and Orchestration approaches
Bucketbench: Benchmarking Container Runtime Performance
Overview of the Open Source Vulkan Driver for Raspberry Pi 4
Ad

Similar to Linux programming (20)

PDF
GNU Compiler Collection - August 2005
PPT
From gcc to the autotools
PDF
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
PPT
Advanced c programming in Linux
PPTX
Gnu debugger
PPTX
GNU Debugger
PDF
The compilation process
PPTX
G++ & GCC
ODP
C Under Linux
ODP
Advanced Linux Game Programming
ODP
Libraries
PPT
Introduction to libraries in india and china
PPTX
Compiling Under Linux
PDF
Debugging embedded devices using GDB
PDF
Linux Internals Part - 2
PPTX
Autotools pratical training
PDF
Whirlwind tour of the Runtime Dynamic Linker
PPT
PPTX
Understanding how C program works
GNU Compiler Collection - August 2005
From gcc to the autotools
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Advanced c programming in Linux
Gnu debugger
GNU Debugger
The compilation process
G++ & GCC
C Under Linux
Advanced Linux Game Programming
Libraries
Introduction to libraries in india and china
Compiling Under Linux
Debugging embedded devices using GDB
Linux Internals Part - 2
Autotools pratical training
Whirlwind tour of the Runtime Dynamic Linker
Understanding how C program works
Ad

Linux programming

  • 1. Programming in the Linux Environment ISO C and POSIX Standards The Development tools Using GCC Creating and Using Libraries Dynamic modules Debugging with GDB
  • 2. What are ISO C and POSIX Standards and Why should we care about them ?
  • 3. The Development tools available in the Linux Environment – Programming Languages Available ✔ C ✔ C++ ✔ Java ✔ Python ✔ C# (CLR comes from the Mono Project) ✔ Perl ✔ Tcl/tk ✔ Vala ✔ Lua ✔ Ada ✔ PHP ✔ Ruby ✔ Haskell, Pascal, Fortran, Lisp,
  • 4. The Development tools available in the Linux Environment – Tools for C Programming • GCC: GNU Compilers Collection • GDB: GNU Debugger • Emacs/Vi: The code editors
  • 5. Using GCC – Writing A “Hello World” Program – Compiling and Running the program gcc -o helloworld helloworld.c ./helloworld
  • 6. Using GCC – Some Essential features of GCC • Including Additional Header Files gcc -I/home/abhinav/code/include include-test.c -o include-test ./include-test
  • 7. Using GCC – Some Essential features of GCC • Linking Libraries • Debugging symbols • Creating libraries
  • 8. Creating and Using Libraries – Libraries are a collection of functions – libm, libpthread, libdbm, libc Types of Libraries: – Static Libraries: .a extension – Dynamic Libraries: .so extension
  • 9. Creating and Using Libraries – Making object files: gcc -I./include -c new-helloworld.c print.c – Linking Object files • Gcc -o new-helloworld new-helloworld.o print.o -c : tells the compiler to only compile the file, but not to link them -o: to specify the name of the output file.
  • 10. Creating and Using Libraries – Creating Static Library: • gcc -o *.c • ar cr libcalc.a *.o – Linking against the static library: gcc -I./include -o calc-test calc-test.c -L. -lcalc
  • 11. Creating and Using Libraries – Creating Shared Library: • gcc -c -fPIC *.c • gcc -shared -fPIC -o libcalc.so *.o – Linking against the shared library: (Same as linking against a static library) gcc -I./include -o calc-test calc-test.c -L. -lcalc
  • 12. Debugging with GDB – Generating debugging symbols: • gcc -g -o Starting the debugger: • gdb <program name> Some common commands: • b line-number or function name: sets the break point • next : step over • step: step in • p <variable name> : prints the value of the variable • where: prints the stack trace • up: moves you up in the stack
  • 13. Dynamically Loading Modules – Concept of Plugins/modules which are loaded by the program at run tim – No dynamic or statical linking of libraries void *handle = dlopen(“libcalc.so”, RTLD_LAZY); void (*test) () = dlsym(handle, “add”); (*test) (); dlclose (handle);
  • 14. Some other productivity tools Diff: What are the changes made in the file Patch: merging the changes Version Control tools: Git, Bazaar, mercurial, SVN, CVS
  • 15. Thank You --Abhinav Upadhyay Twitter: iamabhi9 Irc.freenode.net: abhinav-