December 23rd, 2007
Chapter 29 . Programming Tools and Utilities 789 $ gcc file1.c file2.c file3.c -o progname gcc would create file1.o, file2.o, and file3.o and then link them all together to create progname. As an alternative, you can use gcc s -c option on each file individually, which creates object files from each file. Then in a second step, you link the object files together to create an executable. Thus, the single command just shown becomes: $ gcc -c file1.c $ gcc -c file2.c $ gcc -c file3.c $ gcc file1.o file2.o file3.o -o progname One reason to do this is to avoid recompiling files that haven t changed. If you change the source code only in file3.c, for example, you don t need to recompile file1.c and file2.c to recreate progname. Another reason to compile source code files individually before linking them to create the executable is to avoid longrunning compilation. Compiling multiple files in a single gcc invocation can take a while if one of the source code modules is really lengthy. Let s take a look at an example that creates a single binary executable from multiple source code files. The example program named newhello is comprised of a C source code file, main.c (see Listing 29-1); a header file, msg.h (see Listing 29-2); and another C source code file, msg.c (see Listing 29-3). Listing 29-1: Main Program for newhello /* * main.c _ driver program */ #include #include msg.h int main(int argc, char *argv[]) { char msg_hi[] = { Hi there, programmer! }; char msg_bye[] = { Goodbye, programmer! }; printf( %sn , msg_hi); prmsg(msg_bye); return 0; }
You want to have a cheap webhost for your apache application, then check apache web hosting services.
December 22nd, 2007
788 Part VI . Programming in Linux If you run the program, here s the output you get: $ ./hello Hello, Linux programming world! The command that executed the hello program specifically included the current directory, denoted with a . because having the current directory in your path is a security risk. That is, instead of a $PATH environment variable that resembles /bin:/usr/bin:/usr/local/bin:., it should be /bin:/usr/bin:/usr/ local/bin so that a cracker cannot put a dangerous command in your current directory that happens to match the name of the more benign command you really want to execute. GCC relies on file extensions to determine what kind of source code file it is, that is, in which programming language the source code is written. Table 29-1 lists the most common extensions and how GCC interprets them. Table 29-1 GCC s Filenaming Conventions Extension Type .a, .so Compiled library code .c C language source code .C, .cc C++ language source code .i Preprocessed C source code .ii Preprocessed C++ source code .m Objective-C source code .o Compiled object code .S, .s Assembly language source code Compiling Multiple Source Code Files Most non-trivial programs consist of multiple source files, and each source file must be compiled to object code before the final link step. To do so, pass gcc the name of each source code file it has to compile. GCC handles the rest. The gcc invocation might resemble: Caution
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.
December 21st, 2007
Chapter 29 . Programming Tools and Utilities 787 Using the GCC Compiler The GNU Compiler Collection (GCC) is by far the most dominant compiler (rather, the most dominant collection of compilers) used on Linux systems. It compiles programs written in C, C++, Objective-C, Fortran, Java, and Ada. This chapter focuses on the C compiler. GCC gives programmers extensive control over the compilation process. That process includes up to four stages: preprocessing, compilation, assembly, and linking. You can stop the process after any of these stages to examine the compiler s output at that stage. GCC can also handle the various C dialects, such as ANSI C or traditional (Kernighan and Ritchie) C. You can control the amount and type of debugging information, if any, to embed in the resulting binary. And like most compilers, GCC also performs code optimization. The gcc command invokes the C compiler. To use it, provide it the name of a C source file and use its -o option to specify the name of the output file. gcc will preprocess, compile, assemble, and link the program, generating an executable, often called a binary. Here s the simplest syntax: gcc infile.c [-o outfile] infile.c is a C source code file and -o says to name the output file outfile. The [] characters indicate optional arguments throughout this book. If the name of the output file is not specified, gcc names the output file a.out by default. The following example uses gcc to create the hello program from the source file hello.c. First, the source code: /* * hello.c - canonical hello world program */ #include int main(int argc, char *argv[]) { printf( Hello, Linux programming world!n ); return 0; } Now, to compile and run this program, type $ gcc hello.c -o hello If all goes well, gcc does its job silently and returns to the shell prompt. It compiles and links the source file hello.c (gcc hello.c), creating a binary named hello, as specified using the -o hello argument.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.
December 20th, 2007
786 Part VI . Programming in Linux This chapter discusses the most popular programs and utilities of their types. In most cases, alternatives (and sometimes multiple alternatives) exist, but I cover only one to keep the discussion simple (I try to mention the others just so you re familiar with their names). What constitutes a well-stocked Linux development toolkit? The basics include an editor to write the code, one or more compilers to turn source code into binaries, and a debugger to track down the inevitable bugs. Most people have a favorite editor, and you d have a difficult time trying to persuade them to try a new one. Most editors support some set of programming-related functionality (some more than others, to be sure). There are too many to cover in this space, so suffice it to say: You ll need an editor. Perhaps the most popular editors are vi and emacs. Vi is a commercial editor, being part of the commercial UNIX offerings, so what you can actually get is usually a clone such as vim, elvis, or (my own personal favorite) nvi (new vi). I prefer nvi because it is a port of vi from BSD UNIX to Linux. Other popular editors include pico (the Pine mail client editor made available as a separate program), jed, joe, jove, and nano. If you prefer graphical editors, gedit in GNOME and kedit in KDE also provide basic programming support. Chapter 2 has a short tutorial on using the vi editor, as well as short descriptions of several other popular open source text editors. When it comes to compilers, GCC is the compiler of choice, or, if you will, the choice of the GNU generation, so this chapter discusses only GCC. Other compilers are available for Linux, such as Intel s C and C++ compiler and a very powerful (and expensive) offering from the Portland Compiler Group. Similarly, GDB, the GNU debugger, is the only debugger described in this chapter. In Chapter 28 you examined the role that programming interfaces play in simplifying the development task. Interfaces usually include one or more libraries that implement the functionality that interfaces define. Because you need to be able to work with programming libraries, utilities for creating, examining, and manipulating libraries also occupy the well-stocked programming toolkit. To this list, most developers would add a build automation tool, such as make, because most non-trivial projects need some sort of utility that handles building and rebuilding complicated, multi-file projects with a minimum of effort and time. Another challenge for large projects is tracking source code changes and maintaining a record of what code changed, when it changed, how it changed, and who changed it. This task is the province of source code control systems, and this chapter looks at two: RCS and CVS. Cross- Reference
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.
December 19th, 2007
Programming Tools and Utilities The preceding chapter, Programming Environments and Interfaces, provided a high-level view of Linux programming, focusing on the overall development environment and introducing the idioms that give programming on a Linux system its distinctive character. This chapter goes into greater detail and describes some of the tools and toys found on a typical Linux development system. The goal of this chapter is not to turn you into a developer in 30 pages or less, but simply to explore some of the variety of tools developers use so you will at least know what they are and what they do. You ll also learn how to use some of the programs and utilities. The Well-Stocked Toolkit Whether you prefer a graphical development environment or the classic command-line environment, you need a good set of tools if you want to write, compile, and debug programs for Linux. The good news is that Linux has plenty of editors, compilers, and debuggers from which to choose. The bad news is that Linux has plenty of editors, compilers, and debuggers from which to choose. The range of programming tool options is good news for developers because they can pick the best and most appropriate tools for the development task at hand. The proliferation of choices is bad news for system administrators who need to install and maintain the tools and for people who evaluate the tools. Too many choices make choosing the right one a difficult task. 2C H A9P9T E R . . . . In This Chapter Using the GCC compiler Automating builds with make Examining library utilities Exploring source code control Debugging with GDB . . . .
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
December 18th, 2007
Chapter 28 . Programming Environments and Interfaces 783 This chapter looked at both graphical programming IDEs and the less visually attractive but just as powerful command-line or text-mode programming environments. You also learned some of the characteristics of Linux and of Linux systems that define and shape programming and programs on and for Linux. The second part of the chapter looked at the variety of programming interfaces, the methods available for getting particular programming tasks done. You learned that you can create text-mode or command-line interfaces and that you can choose from a variety of graphical interfaces for structuring user interaction with your program. Finally, you took a fast-paced look at some of the many APIs that make it possible to do a variety of things, such as manipulate or create images or interact with a database. . . .
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.
December 18th, 2007
782 Part VI . Programming in Linux Table 28-1 (continued) API Category Description pilot-link PalmOS pilot-link implements a library for communicating with Palm handheld devices and with other devices that adhere to the PalmOS interface standard. gnome-pilot and KPilot use pilot-link. popt General popt is a C library for parsing command-line parameters. popt was heavily influenced by the getopt() and getopt_long() functions, but improves on them by allowing more powerful argument expansion and allows command-line arguments to be aliased via configuration files. sdl Multimedia The Simple DirectMedia Layer (SDL) provides a generic, cross-platform API for low-level access to audio, keyboards, mice, joysticks, 3D hardware via OpenGL, and 2D framebuffers. t1lib Graphics t1lib provides an API for generating character and string glyphs from Adobe Type 1 fonts. taglib Audio TagLib is a library for reading and editing the meta-data stored in ID3v1 and ID3v2 (MP3 files) and Ogg Vorbis comments and ID3 tags (Ogg Vorbis files). zlib Data zlib provides a general-purpose, thread-safe data Compression compression library that implements the data formats defined by RFC1950, RFC1951, and RFC1952 (see www.ietf.org/rfc.html to find any of the RFCs just mentioned). As you can see, a wide variety of APIs exist for performing an equally wide variety of programming tasks. Chances are pretty good that if you need to perform some sort of programming task, someone has written a library that you can use to do it. Summary The phrase Linux programming environments and interfaces is shorthand that masks a rich set of features, which, taken together, only partially characterize the activity of programming on a Linux system.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.
December 17th, 2007
Chapter 28 . Programming Environments and Interfaces 781 API Category Description libpng Graphics The Portable Network Graphics (PNG) standard is an extensible file format for the lossless, portable, wellcompressed storage of images. PNG provides a patent-free replacement for GIF. libtermcap Hardware libtermcap implements the GNU termcap library API, a library of C functions that enable programs to send control strings to terminals in a way independent of the terminal type. libtiff 2-D Graphics The TIFF library provides an API for working with images stored in the Tag Image File Format (TIFF), a widely used format for storing high-quality, high-resolution images. libungif 2-D Graphics libungif provides an API unencumbered by patents for loading and saving images in GIF format. libusb Hardware libusb allows user space application access to USB devices. libvorbis Audio This library supports the Vorbis General Audio Compression Codec, commonly known as Ogg Vorbis. Ogg Vorbis is an open, patent-and-royalty-free, general-purpose compressed audio format for audio and music. libwmf Graphics libwmf provides an API for interpreting, displaying, and converting metafile images to standard image formats such as PNG, JPEG, PS, EPS, and SVG. libxml2 XML libxml2 is the XML parser library used by GNOME and KDE. libxslt XML libxslt provides XSLT support for libxml2. XSLT is a language used to transform XML documents into other formats. orbit CORBA ORBit is a high-performance Common Object Request Broker Architecture (CORBA) object request broker (ORB). ORBit allows programs to send requests and receive replies from other programs, regardless of the locations of the two programs. GNOME uses ORBit heavily. pango Text layout Pango is a library for layout and rendering of text, with an emphasis on internationalization. Pango forms the core of text and font handling in GTK+-2.0. pcre Regular The Perl-compatible regular expression (PCRE) library expressions implements an API for regular expression pattern matching that uses the same syntax and semantics as Perl 5. The PCRE library is used by many programs. Continued
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.
December 15th, 2007
780 Part VI . Programming in Linux Table 28-1 (continued) API Category Description imlib Graphics ImLib (image library) is an image loading and rendering API designed to simplify and speed up the process of loading images and obtaining X Window System. libao Audio libao is a cross-platform audio library used by other libraries and programs that use audio, including ogg123, GAIM, and the Ogg Vorbis libraries. libart_lgpl 2-D Graphics Libart is a library for high-performance 2D graphics used by KDE and GNOME. libexif Graphics This library provides an API allowing programs to read, parse, edit, and save Exchangeable Image File Format (EXIF) data in image files. EXIF is a format used to store extra information in images, such as the JPEG files produced by digital cameras. libglade Graphics The GLADE library, used heavily in GNOME programs, allows programs to load user interfaces from definitions stored in external files. This allows the interface to be changed without recompiling the program. libid3tag Audio libid3tag is a library for reading ID3 tags. ID3 tags allow extra information to be embedded in audio files. libieee1284 Hardware libieee1284 enables applications that need to communicate with (or at least identify) devices that are attached via IEEE1284-compliant parallel ports, such as scanners. libjpeg Graphics The JPEG library provides a rich API for manipulating JPEGformat images, including reading, writing, converting, compressing, and decompressing images. libmad Audio libmad provides a high-quality MPEG audio decoder API. libmad provides full 24-bit PCM output, so applications using this API can produce high quality audio. libmng Graphics libmng implements the Multiple-image Network Graphics (MNG) API. MNG provides multi-image animation capabilities similar to animated GIFs, but free of patent encumbrances. libogg Audio Libogg is a library for reading and writing ogg format bitstreams. libogg is needed to use the Ogg Vorbis audio format.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.
December 14th, 2007
Chapter 28 . Programming Environments and Interfaces 779 Table 28-1 Common Linux APIs API Category Description aalib ASCII art AA-lib is an ASCII art graphics library output as ASCII art. arts Sound The analog realtime synthesizer (aRts) is KDE s core sound system, designed to create and process sound using small specialized modules. These modules might create a waveform, play samples, filter data, add signals, perform effects (such as delay, flanger, or chorus), or output the data to the soundcard. atk Accessibility atk is a library of accessibility functions used by GNOME. audiofile Audio audiofile, used by the esound daemon (Enlightened Sound Daemon), is a library for processing various audio file formats. You can also use it to develop your own audio file based applications. db4 Database The Berkeley Database (Berkeley DB) library enables developers to create applications with database support. expat XML Expat is a stream-oriented C library for parsing XML. It is used by Python, GNOME, Xft2, and other applications. gdbm Database The GNU Database Manager (GDBM) is a set of database routines that work similarly to the standard UNIX dbm routines. gdk-pixbuf 2-D Graphics GdkPixbuf is an API for loading, scaling, compositing, and animating images. GdkPixBuf is required by many GTK+ programs. glib General GLib is a general purpose API of C language routines. The library includes support for features such as lists, trees, hashes, memory allocation, and many other things. GLib is required by almost every GTK+ application. glut 3-D Graphics The GL Utility Toolkit (GLUT) is a 3D graphics library based on the OpenGL API. It provides a higher-level interface for creation of OpenGL-based graphics. gmp Mathematics The GNU Multiple Precision (GMP) API implements a library for arbitrary precision arithmetic, such as operations on signed integers, rational numbers, and floating-point numbers. gnet Network GNet is an object-oriented library of network routines. Written in C and based on the GLib library, GNet is used by gnomeicu and Pan. Continued
You want to have a cheap webhost for your apache application, then check apache web hosting services.