Programming in the LinuxEnvironmentISO C and POSIX StandardsThe Development toolsUsing GCCCreating and Using LibrariesDynamic modulesDebugging with GDB
What are ISO C and POSIXStandards 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: iamabhi9Irc.freenode.net: abhinav-