Getting Started
Programming Linux
A vast range of programming languages are available for Linux systems, and many of them are free and available on CD-ROM collections or from FTP archive sites on the Internet. Here’s a partial list of programming languages available to the Linux programmer:
ada | C | C++ |
Eiffel | Forth | Fortran |
Icon | Java | JavaScript |
Lisp | Modula 2 | Modula 3 |
Oberon | Objective C | Pascal |
Perl | PostScript | Prolog |
Python | Ruby | Smalltalk |
PHP | Tcl/Tk | Bourne Shell |
we mainly concentrate on C. We direct our attention mostly toward exploring the Linux programming interfaces from the perspective of the C programmer, and we assume knowledge of the C programming language.
Linux Programs
Linux applications are represented by two special types of files: executables
and scripts
. Executable files are programs that can be run directly by the computer; they correspond to Windows .exe files. Scripts are collections of instructions for another program, an interpreter, to follow. These correspond to Windows .bat or .cmd files, or interpreted BASIC programs.
The shell finds the programs you ask for by name by searching for a file with the same name in a given set of directories. The directories to search are stored in a shell variable, PATH
. And some standard places where
system programs are stored include:
/bin:
Binaries, programs used in booting the system/usr/bin:
User binaries, standard programs available to users/usr/local/bin:
Local binaries, programs specific to an installation
Text Editors
The text editors we usually used include: vim, emacs and so on.
The C and C++ Compiler
On most Linux distributions, the gcc
and g++
compilers are used for C programs and C++ programs.
program.c is the source file of the program, program is the name you give to the executable program.
gcc -o program program.c
gcc -I/your/include/path program.c
direct the compiler to look in the directory /your/include/path
, as well as the standard places.
grep text-pattern search-files
searches the files search-files
for the string text-pattern
.
Library Files
Libraries are collections of precompiled functions that have been written to be reusable. Typically, they consist of sets of related functions to perform a common task.
Standard system libraries are usually stored in /lib and /usr/lib. The C compiler (or more exactly, the linker) needs to be told which libraries to search, because by default it searches only the standard C library.
- .a for traditional, static libraries
- .so for shared libraries
The commands used to link to a librarylibm.a
is :
gcc -o program program.c /your/file/path/libm.a
gcc -o program program.c -lm
(The library is in the standard library directories.)
gcc -o program program.c -L/your/lib/path -lm
You can see which shared libraries are required by a program by running the utility ldd
.
Getting Help
The command man
and info
is used to search docs usually.
Summary
In this introductory chapter, we’ve looked at Linux programming and the things Linux holds in common with proprietary UNIX systems. We’ve noted the wide variety of programming systems available to UNIX developers. We’ve also presented a simple program and library to demonstrate the basic C tools, comparing them with their Windows equivalents.