SlideShare uma empresa Scribd logo
1 de 15
Baixar para ler offline
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-

Mais conteúdo relacionado

Mais procurados

OSDC 2017 - Dr. Udo Seidel - VMwares (open source) Way of Container
OSDC 2017 - Dr. Udo Seidel - VMwares (open source) Way of ContainerOSDC 2017 - Dr. Udo Seidel - VMwares (open source) Way of Container
OSDC 2017 - Dr. Udo Seidel - VMwares (open source) Way of ContainerNETWAYS
 
[Szjug] Docker. Does it matter for java developer?
[Szjug] Docker. Does it matter for java developer?[Szjug] Docker. Does it matter for java developer?
[Szjug] Docker. Does it matter for java developer?Izzet Mustafaiev
 
OpenCms Days 2013 - Gradle based OpenCms build automated setup
OpenCms Days 2013 - Gradle based OpenCms build automated setupOpenCms Days 2013 - Gradle based OpenCms build automated setup
OpenCms Days 2013 - Gradle based OpenCms build automated setupAlkacon Software GmbH & Co. KG
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
runC – Open Container Initiative
runC – Open Container InitiativerunC – Open Container Initiative
runC – Open Container InitiativeJeeva Chelladhurai
 
BKK16-407 AOSP Toolchain Evolution and experimental languages on AOSP
BKK16-407 AOSP Toolchain Evolution and experimental languages on AOSPBKK16-407 AOSP Toolchain Evolution and experimental languages on AOSP
BKK16-407 AOSP Toolchain Evolution and experimental languages on AOSPLinaro
 
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTThesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTTuononenP
 
Containers and Orchestration approaches
Containers and Orchestration approachesContainers and Orchestration approaches
Containers and Orchestration approacheskloia
 
Bucketbench: Benchmarking Container Runtime Performance
Bucketbench: Benchmarking Container Runtime PerformanceBucketbench: Benchmarking Container Runtime Performance
Bucketbench: Benchmarking Container Runtime PerformancePhil Estes
 
Overview of the Open Source Vulkan Driver for Raspberry Pi 4
Overview of the Open Source Vulkan Driver for Raspberry Pi  4Overview of the Open Source Vulkan Driver for Raspberry Pi  4
Overview of the Open Source Vulkan Driver for Raspberry Pi 4Igalia
 

Mais procurados (17)

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

Semelhante a Linux programming

Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Annie Huang
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux EnvironmentDongho Kang
 
Introduction to the LLVM Compiler System
Introduction to the LLVM  Compiler SystemIntroduction to the LLVM  Compiler System
Introduction to the LLVM Compiler Systemzionsaint
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSHarrytoye2
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.skGitlab ci, cncf.sk
Gitlab ci, cncf.skJuraj Hantak
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5David Voyles
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Ahmed El-Arabawy
 
betterCode Workshop: Effizientes DevOps-Tooling mit Go
betterCode Workshop:  Effizientes DevOps-Tooling mit GobetterCode Workshop:  Effizientes DevOps-Tooling mit Go
betterCode Workshop: Effizientes DevOps-Tooling mit GoQAware GmbH
 
Continuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CIContinuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CIalexanderkiel
 
“OpenCV: Past, Present and Future,” a Presentation from OpenCV.org
“OpenCV: Past, Present and Future,” a Presentation from OpenCV.org“OpenCV: Past, Present and Future,” a Presentation from OpenCV.org
“OpenCV: Past, Present and Future,” a Presentation from OpenCV.orgEdge AI and Vision Alliance
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applicationsRoman Podoliaka
 
Tech Days 2015: AdaCore Roadmap
Tech Days 2015: AdaCore RoadmapTech Days 2015: AdaCore Roadmap
Tech Days 2015: AdaCore RoadmapAdaCore
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureQAware GmbH
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLMario-Leander Reimer
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerGonçalo Gomes
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - IntroductionRakesh Jha
 
Knative build for open whisk runtimes phase 1 - 2018-02-20
Knative build for open whisk runtimes   phase 1 - 2018-02-20Knative build for open whisk runtimes   phase 1 - 2018-02-20
Knative build for open whisk runtimes phase 1 - 2018-02-20Matt Rutkowski
 
Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015Kurt Madel
 

Semelhante a Linux programming (20)

Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux Environment
 
Introduction to the LLVM Compiler System
Introduction to the LLVM  Compiler SystemIntroduction to the LLVM  Compiler System
Introduction to the LLVM Compiler System
 
Php on Windows
Php on WindowsPhp on Windows
Php on Windows
 
OpenCV Workshop
OpenCV WorkshopOpenCV Workshop
OpenCV Workshop
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oS
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.skGitlab ci, cncf.sk
Gitlab ci, cncf.sk
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
betterCode Workshop: Effizientes DevOps-Tooling mit Go
betterCode Workshop:  Effizientes DevOps-Tooling mit GobetterCode Workshop:  Effizientes DevOps-Tooling mit Go
betterCode Workshop: Effizientes DevOps-Tooling mit Go
 
Continuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CIContinuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CI
 
“OpenCV: Past, Present and Future,” a Presentation from OpenCV.org
“OpenCV: Past, Present and Future,” a Presentation from OpenCV.org“OpenCV: Past, Present and Future,” a Presentation from OpenCV.org
“OpenCV: Past, Present and Future,” a Presentation from OpenCV.org
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Tech Days 2015: AdaCore Roadmap
Tech Days 2015: AdaCore RoadmapTech Days 2015: AdaCore Roadmap
Tech Days 2015: AdaCore Roadmap
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
Knative build for open whisk runtimes phase 1 - 2018-02-20
Knative build for open whisk runtimes   phase 1 - 2018-02-20Knative build for open whisk runtimes   phase 1 - 2018-02-20
Knative build for open whisk runtimes phase 1 - 2018-02-20
 
Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015
 

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-