Datasheet
How It Works
You invoked the GNU C compiler (on Linux this will most likely be available as cc too) that translated
the C source code into an executable file called
hello. You ran the program and it printed a greeting.
This is just about the simplest example there is, but if you can get this far with your system, you should
be able to compile and run the remainder of the examples in the book. If this did not work for you, make
sure that the C compiler is installed on your system. For example, many Linux distributions have an
install option called Software Development (or something similar) that you should select to make sure
the necessary packages are installed.
Because this is the first program you’ve run, it’s a good time to point out some basics. The
hello pro-
gram will probably be in your home directory. If
PATH doesn’t include a reference to your home direc-
tory, the shell won’t be able to find
hello. Furthermore, if one of the directories in PATH contains
another program called
hello, that program will be executed instead. This would also happen if such a
directory is mentioned in
PATH before your home directory. To get around this potential problem, you
can prefix program names with
./ (for example, ./hello). This specifically instructs the shell to execute
the program in the current directory with the given name. (The dot is an alias for the current directory.)
If you forget the
-o name option that tells the compiler where to place the executable, the compiler will
place the program in a file called
a.out (meaning assembler output). Just remember to look for an
a.out if you think you’ve compiled a program and you can’t find it! In the early days of UNIX, people
wanting to play games on the system often ran them as
a.out to avoid being caught by system adminis-
trators, and some UNIX installations routinely delete all files called
a.out every evening.
Development System Roadmap
For a Linux developer, it can be important to know a little about where tools and development resources
are located. The following sections provide a brief look at some important directories and files.
Applications
Applications are usually kept in directories reserved for them. Applications supplied by the system for
general use, including program development, are found in
/usr/bin. Applications added by system
administrators for a specific host computer or local network are often found in
/usr/local/bin or /opt.
Administrators favor
/opt and /usr/local, because they keep vendor-supplied files and later addi-
tions separate from the applications supplied by the system. Keeping files organized in this way may
help when the time comes to upgrade the operating system, because only
/opt and /usr/local need
be preserved. We recommend that you compile your applications to run and access required files from
the
/usr/local hierarchy for system-wide applications. For development and personal applications it’s
best just to use a folder in your
home directory.
Additional features and programming systems may have their own directory structures and program
directories. Chief among these is the X Window System, which is commonly installed in the
/usr/X11 or
/usr/bin/X11 directory. Linux distributions typically use the X.Org Foundation version of the X Window
System, based on Revision 7 (X11R7). Other UNIX-like systems may choose different versions of the X
Window System installed in different locations, such as
/usr/openwin for Sun’s Open Windows provided
with Solaris.
8
Chapter 1: Getting Started
47627c01.qxd:WroxPro 9/28/07 8:56 PM Page 8