January 2nd, 2008
Chapter 29 . Programming Tools and Utilities 799 The output might be different on your system. The ldconfig Command ldconfig determines the runtime links required by shared libraries that are located in /usr/lib and /lib, specified in libs on the command line, and stored in /etc/ ld.so.conf. It works in conjunction with ld.so, the dynamic linker/loader, to create and maintain links to the most current versions of shared libraries available on a system. It has the following syntax: ldconfig [options] [libs] A bare ldconfig simply updates the cache file, /etc/ld.so.cache. options controls ldconfig s behavior. The -v option tells ldconfig to be verbose as it updates the cache. The -p option says to print without updating the current list of shared libraries about which ld.so knows. Environment Variables and Configuration Files The dynamic linker/loader ld.so uses a number of environment variables to customize and control its behavior. These variables include: . $LD_LIBRARY_PATH This variable contains a colon-separated list of directories in which to search for shared libraries at runtime. It is similar to the $PATH environment variable. . $LD_PRELOAD This variable is a whitespace-separated list of additional, user-specified shared libraries to load before all other libraries. It is used selectively to override functions in other shared libraries. ld.so also uses two configuration files whose purposes parallel those environment variables: . /etc/ld.so.conf Contains a list of directories that the linker/loader should search for shared libraries in addition to the standard directories, /usr/lib and /lib. . /etc/ld.so.preload Contains a disk-based version of the $LD_PRELOAD environment variable, including a whitespace-separated list of shared libraries to be loaded prior to executing a program. You can use $LD_PRELOAD to override installed versions of a library with a specific version; this is often useful when you are testing a new (or different) library version but don t want to install the replacement library on your system.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.
Posted in PHP5 | No Comments »
January 1st, 2008
798 Part VI . Programming in Linux Table 29-4 ar Command-Line Options Option Description -c Suppresses the warning ar would normally emit if the archive doesn t already exist. -q Adds files to the end of archive without checking for replacements. -r Inserts files into archive, replacing any existing members whose name matches that being added. New members are added at the end of the archive. -s Creates or updates the map linking symbols to the member in which they are defined. Given an archive created with the ar command, you can speed up access to the archive by creating an index to the archive. ranlib does precisely this, storing the index in the archive file itself. ranlib s syntax is: ranlib [-v|-V] file This generates a symbol map in file. It is equivalent to ar -s file. The ldd Command While nm lists the symbols defined in an object file, unless you know what library defines which functions, it is not terribly helpful. That is ldd s job. It lists the shared libraries that a program requires to run. Its syntax is: ldd [options] file ldd prints the names of the shared libraries file requires. Two of ldd s most useful options are -d, which reports any missing functions, and -r, which reports missing functions and missing data objects. For example, the following ldd reports that the mail client mutt (which may or may not be installed on your system) requires eight shared libraries. $ ldd /usr/bin/mutt libncursesw.so.5 => /lib/libncursesw.so.5 (0×40021000) libssl.so.0 => /usr/lib/libssl.so.0 (0×40066000) libcrypto.so.0 => /usr/lib/libcrypto.so.0 (0×40097000) libc.so.6 => /lib/libc.so.6 (0×40195000) libgpm.so.1 => /lib/libgpm.so.1 (0×402c5000) libdl.so.2 => /lib/libdl.so.2 (0×402cb000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0×40000000) libncurses.so.5 => /lib/libncurses.so.5 (0×402ce000) Tip
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.
Posted in PHP5 | No Comments »
December 30th, 2007
Chapter 29 . Programming Tools and Utilities 797 nm lists the symbols stored in file, which must be a static library or archive file, as described in the preceding section. options controls nm s behavior. Table 29-3 describes useful options for nm. Table 29-3 nm Command-Line Options Option Description -C Converts symbol names into user-level names. This is especially useful for making C++ function names readable. -l Uses debugging information to print the line number where each symbol is defined, or the relocation entry if the symbol is undefined. -s When used on archive (.a) files, prints the index that maps symbol names to the modules or members in which the symbol is defined. -u Displays only undefined symbols, symbols defined externally to the file being examined. Here s an example that uses nm to show some of the symbols in /usr/lib/libdl.a: $ nm /usr/lib/libdl.a | head dlopen.o: 00000040 T __dlopen_check U _dl_open U _dlerror_run 00000040 W dlopen 00000000 t dlopen_doit dlclose.o: U _dl_close The ar Command ar creates, modifies, or extracts archives. It is most commonly used to create static libraries, which are files that contain one or more object files. ar also creates and maintains a table that cross-references symbol names to the members in which they are defined. The ar command has the following syntax: ar {dmpqrtx} [options] [member] archive file […] ar creates the archive named archive from the file(s) listed in file. At least one of d, m, p, q, r, t, and x is required. You will usually use r. Table 29-4 lists the most commonly used ar options.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.
Posted in PHP5 | No Comments »
December 30th, 2007
796 Part VI . Programming in Linux names to the members in which the symbols are defined. The map speeds up compilation and linking. Static libraries are typically named with the extension .a, which stands for archive. . Shared libraries Like static libraries, shared libraries are files that contain other object files or pointers to other object files. They are called shared libraries because the code they contain is not linked into programs when the programs are compiled. Rather, the dynamic linker/loader links shared library code into programs at runtime. Shared libraries have several advantages over static libraries. First, they require fewer system resources. They use less disk space because shared library code is not compiled into each binary but linked and loaded from a single location dynamically at runtime. They use less system memory because the kernel shares the memory the library occupies among all the programs that use the library. Second, shared libraries are slightly faster because they need to be loaded into memory only once. Finally, shared libraries simplify code and system maintenance. As bugs are fixed or features added, users need only obtain the updated library and install it. With static libraries, each program that uses the library must be recompiled. The dynamic linker/loader, ld.so, links symbol names to the appropriate shared library in which they are defined at runtime. Shared libraries have a special name, the soname, that consists of the library name and the major version number. The full name of the C library on one of my systems, for example, is libc-2.3.4.so. The library name is libc.so; the major version number is 2; the minor version number is 3; and the release or patch level is 4. For historical reasons, the C library s soname is libc.so.6. Minor version numbers and patch level numbers change as bugs are fixed, but the soname remains the same and newer versions are usually compatible with older versions. I emphasize the soname because applications link against it. How does linking work? The ldconfig utility creates a symbolic link from the actual library, say libc-2.3.2.so, to the soname, libc.so.6, and stores this information in /etc/ld.so.cache. At runtime, ld.so scans the cache file, finds the required soname and, because of the symbolic link, loads the actual library into memory and links application function calls to the appropriate symbols in the loaded library. The nm Command The nm command lists all of the symbols encoded in an object or binary file. It s used to see what function calls a program makes or to see if a library or object file provides a needed function. nm has the following syntax: nm [options] file
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.
Posted in PHP5 | No Comments »
December 29th, 2007
Chapter 29 . Programming Tools and Utilities 795 The sixth rule defines a target named realclean. It uses the fifth rule as one of its dependencies. This causes make to build the clean target and then to remove the editor binary. Here is where make s value becomes evident: Ordinarily, if you tried to build editor using the command from the second line, gcc would complain loudly and ceremoniously quit if the dependencies did not exist. Make, on the other hand, after determining that editor requires these files, first verifies that they exist and, if they don t, executes the commands to create them. After creating the dependencies, make returns to the first rule to create the editor executable. Of course, if the dependencies for the components, editor.c, screen.c, or keyboard.c, don t exist, make gives up because it lacks targets named, in this case, editor.c, screen.c, or keyboard.c (that is, no rules are defined in the makefile for creating editor.c, screen.c, and keyboard.c). All well and good, you are probably thinking, but how does make know when to build or rebuild a file? The answer is simple: If a specified target does not exist in a place where make can find it, make builds or rebuilds it. If the target does exist, make compares the timestamp on the target to the timestamp on the dependencies. If one or more of the dependencies is newer than the target, make rebuilds that target, assuming that the newer dependency implies some code change that must be incorporated into the target. Library Utilities Programming libraries are collections of code that can be reused across multiple software projects. Libraries are a classic example of software development s ardent goal: code reuse. They collect frequently used programming routines and utility code into a single location. The standard C libraries, for example, contain hundreds of frequently used routines, such as the output function printf() and the input function getchar() that would be wearisome to rewrite each time you create a new program. Beyond code reuse and programmer convenience, however, libraries provide a great deal of thoroughly debugged and well-tested utility code, such as routines for network programming, graphics handling, data manipulation, and system calls. You need to know the tools at your disposal for creating, maintaining, and managing programming libraries. There are two types of libraries: static and shared: . Static libraries Static libraries are specially formatted files that contain object files, called modules or members, of reusable, precompiled code. They are stored in a special format along with a table or map that links symbol
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.
Posted in PHP5 | No Comments »
December 28th, 2007
794 Part VI . Programming in Linux Listing 29-4: A Sample Makefile editor : editor.o screen.o keyboard.o gcc -o editor editor.o screen.o keyboard.o editor.o : editor.c gcc -c editor.c screen.o : screen.c gcc -c screen.c keyboard.o : keyboard.c gcc -c keyboard.c clean : rm -f *.o core *~ realclean : clean rm -f editor To compile editor, you simply type make in the directory that contains the makefile. It s that simple. This example makefile has six rules. The first defines how to create the target named editor. The first target in every makefile is the default target (unless you specifically define one using the .DEFAULT directive, which is not covered in this chapter). The default target is the one that make builds if no target is specified as an argument to make. editor has three dependencies: editor.o, screen.o, and keyboard.o; these three files must exist to build editor. The second line in the first rule is the command that make must execute to create editor: gcc -o editor editor.o screen.o keyboard.o. It builds the executable from the three object files: editor.o, screen.o, and keyboard.o. The next three rules tell make how to build the individual object files. Each rule consists of one object file target (editor.o, screen,o, keyboard.o); one source code file dependency (editor.c, screen.c, keyboard.c); and a rule that defines how to build that target. The fifth rule defines a target named clean with no dependencies. When a target has no dependencies, its commands are executed whenever the target is invoked. In this case, clean deletes the constituent object files (*.o), plus any core files (core) as well as any Emacs backup files (*~) from previous builds.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.
Posted in PHP5 | No Comments »
December 27th, 2007
Chapter 29 . Programming Tools and Utilities 793 test followed by make install. Most users appreciate the convenience of simple build instructions. Finally, make speeds up the edit-compile-debug process. It minimizes rebuild times because it is smart enough to determine which files have changed, and recompiles only files that have changed. So, how does make accomplish its magical feats? By using a makefile, which contains rules that tell make what to build and how to build it. A rule consists of the following: . Target The thing make ultimately tries to create . Dependencies A list of one or more dependencies (usually files) required to build the target . Commands A list of commands to execute to create the target from the specified dependencies Makefiles constitute a database of dependency information for the programs they build and automatically verify that all of the files necessary for building a program are available. When invoked, GNU make looks for a file named GNUmakefile, makefile, or Makefile, in that order. For some reason, most developers use the last form, Makefile. Makefile rules have the general form target : dependency dependency […] command command […] target is usually the file, such as a binary or object file, to create. dependency is a list of one or more files required as input to create target. Each command is a step such as a compiler invocation or a shell command that is necessary to create target. Unless specified otherwise, make does all of its work in the current working directory. The first character in a command must be the tab character; eight spaces will not suffice. This often catches people unaware, and can be a problem if your preferred editor helpfully translates tabs to eight spaces. If you try to use spaces instead of a tab, make displays the message Missing separator and stops. Listing 29-4 shows a sample makefile for building a text editor imaginatively named editor. Caution
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.
Posted in PHP5 | No Comments »
December 26th, 2007
792 Part VI . Programming in Linux Table 29-2 (continued) Option Description -static Links against static libraries. -traditional Supports the Kernighan and Ritchie C syntax (if you don t understand what this means, don t worry about it). -v Shows the commands used in each step of compilation. -W Suppresses all warning messages. -Wall Emits all generally useful warnings that gcc can provide. Specific warnings can also be flagged using -Wwarning, where warning is replaced a string identifying an item for which you want to list warnings. -werror Converts all warnings into errors, stopping the compilation. As mentioned earlier, -o file tells GCC to place output in the file file regardless of the output being produced. If you do not specify -o, for an input file named file.suffix, the defaults are to name the executable a.out, the object file file.o, and the assembly language file file.s. Preprocessor output goes to stdout. Automating Builds with make The make utility is a tool to control the process of building and rebuilding software. Make automates what software gets built, how it gets built, and when it gets built, freeing programmers to concentrate on writing code. It also saves a lot of typing, because it contains logic that invokes GCC compiler-appropriate options and arguments. Use this section to familiarize yourself with the look and layout of makefiles. For all but the simplest software projects, make is essential. In the first place, projects composed of multiple source files require long, complex compiler invocations. Make simplifies this by storing these difficult command lines in the makefile, a text file that contains all of the commands required to build software projects. Make is convenient for both the developer and the user who want to build a program. As developers make changes to a program, whether to add new features or incorporate bug fixes, make makes it possible to rebuild the program with a single, short command. Make is convenient for users because they don t have to read reams of documentation explaining in excruciating, mind-numbing detail how to build a program. Rather, they can simply be told to type make followed by make
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.
Posted in PHP5 | No Comments »
December 25th, 2007
Chapter 29 . Programming Tools and Utilities 791 Before it creates the newhello binary, gcc creates object files for each source file. Typing long commands such as this does become tedious, however. The section Automating Builds with make later in this chapter shows you how to avoid having to type long, involved command lines. GCC Command-Line Options The list of command-line options GCC accepts runs to several pages, so Table 29-2 describes only the most common ones. (Type man gcc to see a more complete list of options available with gcc.) Table 29-2 GCC Command-Line Options Option Description -ansi Supports the ANSI/ISO C standard, turning off GNU extensions that conflict with the standard. -c Compiles without linking, resulting in an object file but not an executable binary. -Dfoo=bar Defines a preprocessor macro foo with a value of bar on the command line. -g Includes standard debugging information in the binary. -ggdb Includes lots of debugging information in the binary that only the GNU debugger (GDB) can understand. -Idirname Prepends dirname to the list of directories searched for include files. -Ldirname Prepends dirname to the list of directories searched for library files. By default, gcc links against shared libraries. -lfoo Links against libfoo. -MM Outputs a make-compatible dependency list. -o file Creates the output file file (not necessary when compiling object code). If file is not specified, the default is a.out. -O Optimizes the compiled code. -On Specifies an optimization level n, 0<=n<=3. -pedantic Emits all warnings required by the ANSI/ISO C standard. -pedantic-errors Emits all errors required by the ANSI/ISO C standard. Continued
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
Posted in PHP5 | No Comments »
December 24th, 2007
790 Part VI . Programming in Linux Listing 29-2: Header file for newhello Helper Function /* * msg.h - header for msg.c */ #ifndef MSG_H_ #define MSG_H_ void prmsg(char *msg); #endif /* MSG_H_ */ Listing 29-3: Definitions for newhello Helper Function /* * msg.c - function declared in msg.h */ #include #include msg.h void prmsg(char *msg) { printf( %sn , msg); } The command to compile these programs to create newhello is $ gcc msg.c main.c -o newhello To create the object files individually, you might use the following commands: $ gcc -c msg.c $ gcc -c main.c Then, to create newhello from the object files, use the following command: $ gcc msg.o main.o -o newhello When you run this program, the output is: $ ./newhello Hi there, programmer! Goodbye, programmer!
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.
Posted in PHP5 | No Comments »