Linux programming

410 views
347 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
410
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Linux programming

  1. 1. Programming in the LinuxEnvironmentISO C and POSIX StandardsThe Development toolsUsing GCCCreating and Using LibrariesDynamic modulesDebugging with GDB
  2. 2. What are ISO C and POSIXStandards and Why should we care about them ?
  3. 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. 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. 5. Using GCC– Writing A “Hello World” Program– Compiling and Running the program gcc -o helloworld helloworld.c ./helloworld
  6. 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. 7. Using GCC– Some Essential features of GCC • Linking Libraries • Debugging symbols • Creating libraries
  8. 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. 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. 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. 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. 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. 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. 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. 15. Thank You --Abhinav Upadhyay Twitter: iamabhi9Irc.freenode.net: abhinav-

×