Building and Installing Glibc
Total Page:16
File Type:pdf, Size:1020Kb
APPENDIX A Building and Installing Glibc THE GNU C LIBRARY, popularly known as Glibc, is the unseen force that makes GCC, most C language applications compiled with GCC on Linux systems, and all GNU /Linux systems themselves work. Any code library provides a set of func tions that simplify writing certain types of applications. In the case of the GNU C library, the applications facilitated by Glibc are any C programming language applications. The functions provided by Glibc range from functions as funda mental to C as printf () all the way to Portable Operating System Interface for Computer Environments (POSIX) functions for opening low-level network con nections (more about the latter later). Rebuilding and changing the library on which almost every GNU /Linux appli cation depends can be an intimidating thought. Luckily, it is not as problematic or complex as you might think. This chapter explains how to obtain, build, and install newer versions of the GNU C library, discusses problems that you might encounter, and also explains how to work around those problems in order to get your system(s) up and running with newer or alternate versions of the GNU C library that may be present by default on the system(s) that you are using. NOTE The most important requirement for upgrading Glibc on your system is having sufficient disk space to download and build the source code, back up files that you want to preserve in case you encounter upgrade problems, and install the new version ofGlibc. You should make sure that your system has approximately 200MB offree space in order to build and install Glibc. What Is in Glibc? Because most of the fundamental Un*x, Linux, Hurd, and *BSD applications are written in the C programming language, every Unix-like operating system needs a C library to provide the basic capabilities required in C applications and to provide the system calls that enable C applications to interface with the operat ing system. The GNU C library, Glibc, is the one true C library in the GNU system and most newer systems with the Linux kernel. 363 Appendix A The contents of interfaces provided as part of Glibc have evolved over time and reflect the history of Unix and relevant standards. Glibc provides support for the following standards and major Un*x variants: • Berkeley (BSD): No one with any history on Un*x systems could be unaware of the enhancements to Un*x that were provided by the Berkeley Standard Distribution. NetBSD, FreeBSD, and even Apple's Mac OS X still carry the flag of many of the networking, II 0, and usability improvements made to Un*x by the University of California at Berkeley and other academic insti tutions such as Carnegie Mellon University, and long-lived BSD-based Un*x implementations such as Sun Microsystems' SunOS. Glibc supports many of the capabilities found in the 4.2 BSD, 4.3 BSD, and 4.4 BSD Unix systems, and in SunOS. This heightens code compatibility with 4.4 BSD and later SunOS 4.X distributions, which themselves support almost all of the capabilities of the ISO C and POSIX standards. • ISO C: This is the C programming language standard adopted by the American National Standards Institute (ANSI) in "American National Standard X3.159-1989-ANSI C," and later by the International Standardization Organization (ISO) in their "ISO/IEC 9899:1990, Programming languages-C." This is colloquially referred to as the ISO C standard throughout the Glibc documentation. NOTE The header files and functions provided by Glibc are a superset ofthose specified in the ISO C standard. Ifyou need to write applications that strictly follow the ISO C standard, you must use the -ansi option when compiling programs with GCC. This will identify any non-ANSI constructs that you might have used accidentally. • POSIX: This is the Portable Operating System Interface for Computer Environments (ISO/IEC 9945-1:1996), later adopted by ANSI and IEEE as ANSI/IEEE Std 1003. The POSIX standard has its roots in Unix systems, and was designed as a standard that would facilitate developing appli cations that could be compiled across all compliant Un*x systems. The POSIX standard is a superset of the ISO C standard, adding new functions and extending existing functions in the ISO C standard. If you need to sling applicable acronyms, the Glibc manual states that Glibc is compliant with POSIX, POSIX.1, IEEE Std 1003.1 (and IEEE Std 1003.2, Draft 11), ISO/IEC 9945-1, POSIX.2, and IEEE Std 1003.2. Glibc also implements some of the functionality required in the "POSIX Shell and Utilities" standard (a.k.a. POSIX.2 or ISO/IEC 9945-2:1993). 364 Building and Installing Glibc • SYSV Unix: Un*x history began at AT&T Bell Labs. Glibc supports the majority of the capabilities specified in the AT&T "System V Interface Description" (SVID) document, which is a superset of the POSIX standard mentioned earlier. • XPG: The "X/ Open Portability Guide," published by the X/ Open Company, Ltd., is a general Un*x standard. This document specifies the requirements for systems that are intended to be conformant Unix systems. Glibc com plies with the "X/ Open Portability Guide, Issue 4.2," and supports all of the X/ Open System Interface (XSI) and X/ Open Unix extensions. This should not be a big surprise, since the majority of these are derived from enhance ments to Unix made on System V or BSD Unix, and Glibc is compliant with those. Today's Glibc has come a long way from the statically linked version l.x Glibc of the 1980s. Today, Glibc is a powerful set of shared libraries that is used on hundreds of thousands of computer systems all over the world. Like GCC, Glibc is a living testimonial to the power of open source software and the insight and philanthropy of its designers and contributors. Alternatives to Glibc The completeness and power of Glibc has an unfortunate, but not unsurprising, side effect-Glibc is big. Glibc is also a shared library, which has distinct admin istrative and performance improvements for desktop and server systems, but may not be desirable in all circumstances. The most notable environment in which you may not want all of the overhead of Glibc is in embedded systems running Linux. Linux is becoming incredibly popular for use in embedded sys tems because of its power, flexibility, and huge code base-and also because using generic Linux in an embedded system eliminates the need for operating system royalty payments. There are two popular alternatives to Glibc, both targeted for use in embed ded systems. The next two sections provide an overview of each of these and information about how to obtain them. These sections do not discuss how to install and use them, as this is somewhat outside the scope of a chapter dedi cated to Glibc. NOTE Depending upon your application and the system that you are devel oping for. you may also want to statically link applications in order to conserve memory and eliminate library access time on embedded systems. 365 Appendix A uClibc: The Micro C Library The micro C library, uClibc, is a C library for developing embedded Linux sys tems. It is much smaller than the GNU C library, but provides almost all of the functionality of Glibc without approaching its size. In most cases, porting appli cations from Glibc to uClibc simply requires recompiling the source code, linking against uClibc rather than Glibc. NOTE The letter u is short for the Greek letter mu, which resembles a lower case u and is commonly used as the abbreviation for the word micro. The capital C is an abbreviation for the word controller. uClibc is generally pro nounced as "yew-see-lib-see," or as "mew-see-lib-see" by the more technically obsessed. uClibc is maintained by Erik Andersen (also the author and maintainer of BusyBox, another favorite of embedded linux developers). uClibc is licensed under the GNU library General Public license. This license enables you to build and distribute commercial applications using uClibc without requiring that you provide the source code for them-you can still own your own intellectual property if youso desire. For more information about uClibc, see its home page at http:/ /www.uclibc.org/. You can obtain the source code for the latest version of uClibc there or at the uClibc project page at Freshmeat.net (http:/ /freshmeat.net/projects/uclibc/). The latest version ofuClibc was 0.9.19 at the time this book was written. New lib Newlib is an alternative to Glibc (and uClibc) that was originally developed for use in embedded systems by Cygnus Software (later acquired by Red Hat), and is still maintained by people at Red Hat (Jeff Johnston and Tom Fitzsimmons). With the purchase of Cygnus Software, Red Hat made a substantial move into the embedded development market from which they have subsequently retreated with somewhat oxymoronic statements along the lines of"You can just take your desktop or enter prise Red Hat distribution and scale it down for use on an embedded system." Though this is much like saying "You can just use your Cadillac as a sports car if you shave down the body and put on smaller tires," that is their position. This does not detract from the usability and value ofNewlib in embedded systems, however. For more information about Newlib, see its home page at http:/ /sources.redhat.com/newlib/. You can also download the source code for 366 Building and Installing Glibc the latest version ofNewlib there.