- Introduction to GNU C and C++ Compilers
- Installing GNU Compiler
- Compiling a Program
- Linking a program
- Assembling a Program
- Handling Warning and Error messages
- Include files
- Creating Libraries
- Standard Libraries
- Compiling Pascal Programs
- Compiling Fortran Programs
- Other Compilers
- References and Resources
3.9 Standard Libraries
In addition to the compiler, assembler, linker and other tools, you also need standard library files. All Linux distributions come with the GNU C library which is installed as glibc. However, when you are building your development environment, you may need to get the library in source code format and install the latest version. You may also need the library in source code format in order to cross compile it when you are building a cross-compilation environment. The standard GNU C library provides functions for the following major areas.
Strings and arrays
Locales and international specific things, like character handling and date and time specific functions
Input and output
File system support
Date and time functions
Signal and exception handling
User and groups
System related tasks
Information about glibc is available on http://www.gnu.org/software/libc/libc.html. You can download it from ftp://ftp.gnu.org/gnu/glibc/ where you can find the latest as well as old versions. The current version at the time of writing this book is 2.2.5.
After downloading the library, you have to untar it. For the sake of this book, I untarred the library file in /opt directory. The following tar command extracts library files in /opt/glibc-2.2.5 directory.
tar zxvf glibc-2.2.5.tar.gz
Now you have to extract any other components or add-ons of the library. I have added one component, Linux threads. File glibc-linuxthreads-2.2.5.tar.gz can also be downloaded from the same location from which you downloaded the main glibc-2.2.5.tar.gz file. The following commands are used to extract files from these two archives:
cd glibc-2.2.5 tar zxvf ../ glibc-linuxthreads-2.2.5.tar.gz
In old versions of glibc, you had to install add-ons like locale data and crypt library. These are included in the latest version of glibc.
Now you have to configure the library after creating a build directory. Basically this is the same process that you have done while installing GCC and binutils. This is done using the following set of commands:
[root@conformix glibc-2.2.5]# mkdir build [root@conformix glibc-2.2.5]# cd build [root@conformix build]# ../configure --enable-add-ons=linuxthreads --prefix=/opt/gcc-3.0.4
The actual compilation and testing is done using the following two commands:
make make check
The final install command is the following:
This command will install components of GNU C library under /opt/gcc-3.0.4/lib because we had chosen /opt/gcc/3.0.4 as our prefix when we ran the configure script. Now you can set the appropriate paths in your Makefiles to use the new library.