<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML> <HEAD> <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9"> <TITLE>Glibc 2 HOWTO: Compiling with the non-primary libc.</TITLE> <LINK HREF="Glibc2-HOWTO-7.html" REL=next> <LINK HREF="Glibc2-HOWTO-5.html" REL=previous> <LINK HREF="Glibc2-HOWTO.html#toc6" REL=contents> </HEAD> <BODY> <A HREF="Glibc2-HOWTO-7.html">Next</A> <A HREF="Glibc2-HOWTO-5.html">Previous</A> <A HREF="Glibc2-HOWTO.html#toc6">Contents</A> <HR> <H2><A NAME="s6">6. Compiling with the non-primary libc.</A></H2> <P> <!-- glibc!compiling with alternate library --> <P>There are times you will want to use an alternate library to compile your programs with. This section explains how to accomplish this, using the directories and installation names used in the examples in the previous two sections. Remember to change the names to fit your setup. <P> <H2><A NAME="ss6.1">6.1 A warning when using non-primary libcs.</A> </H2> <P> <!-- glibc!compiling with alternate library!warning --> Before compiling any programs which is used in the system boot process, remember that if the program is dynamically linked and is used before the non-root partitions are mounted, all linked libraries must be on the root partition. Following the installation process in the previous section for installing glibc as your primary C library, the old libc is left in <CODE>/lib</CODE>, which will be on your root partition. This means all of your programs will still work during booting. However, if <CODE>/usr</CODE> is on a different partition and you install glibc as a test library in <CODE>/usr/i486-linuxglibc2</CODE>, any new programs you compile with glibc will not work until your <CODE>/usr</CODE> partition is mounted. <P> <H2><A NAME="ss6.2">6.2 Compiling programs with a test glibc.</A> </H2> <P> <!-- glibc!compiling with alternate library!glibc --> To compile a program with a test-install glibc, you need to reset the include paths to point to the glibc includes. Specifying "-nostdinc" will negate the normal paths, and "-I/usr/i486-linuxglibc2/include" will point to the glibc includes. You will also need to specify the gcc includes, which are found in <CODE>/usr/lib/gcc-lib/i486-linuxglibc2/2.7.2.2/include</CODE> (assuming you installed the test lib in i486-linuxglibc2 with gcc version 2.7.2.2). <P>To link a program with a test-install glibc, you need to specify the gcc setup. This is done by using the option "-b i486-linuxglibc2". <P>For most programs, you can specify these new options by adding them to the <CODE>$CFLAGS</CODE> and <CODE>$LDFLAGS</CODE> makefile options: <BLOCKQUOTE><CODE> <PRE> CFLAGS = -nostdinc -I/usr/i486-linuxglibc2/include -I/usr/lib/gcc-lib/i486-linuxglibc2/2.7.2.2/include -b i486-linuxglibc2 LDFLAGS = -b i486-linuxglibc2 </PRE> </CODE></BLOCKQUOTE> If you are using a configure script, define the <CODE>$CFLAGS</CODE> and <CODE>$LDFLAGS</CODE> shell variables (by using env/setenv for csh/tcsh, or set/export for sh/bash/etc) before running configure. The makefiles generated by this should contain the proper <CODE>$CFLAGS</CODE> and <CODE>$LDFLAGS</CODE>. Not all configure scripts will pick up the variables, so you should check after running configure and edit the makefiles by hand if necessary. <P>If the programs you are compiling only call gcc (and not cpp or binutils directly), you can use the following script to save having to specify all of the options each time: <BLOCKQUOTE><CODE> <PRE> #!/bin/bash /usr/bin/gcc -b i486-linuxglibc2 -nostdinc \ -I/usr/i486-linuxglibc2/include \ -I/usr/lib/gcc-lib/i486-linuxglibc2/2.7.2.2/include "$@" </PRE> </CODE></BLOCKQUOTE> You can then use this script instead of "gcc" when compiling. <P> <H2><A NAME="ss6.3">6.3 Compiling programs with libc 5 when glibc is primary library.</A> </H2> <P> <!-- glibc!compiling with alternate library!libc 5 --> To compile a program with your old libraries when you have installed glibc as your main library, you need to reset the include paths to the old includes. Specifying "-nostdinc" will negate the normal paths, and "-I/usr/i486-linuxlibc5/include" will point to the glibc includes. You must also specify "-I/usr/lib/gcc-lib/i486-linuxlibc5/2.7.2.2/include" to include the gcc specific includes. Remember to adjust these paths based on the what you named the new directories and your gcc version. <P>To link a program with your old libc, you need to specify the gcc setup. This is done by using the option "-b i486-linuxlibc5". <P>For most programs, you can specify these new options by appending them to the <CODE>$CFLAGS</CODE> and <CODE>$LDFLAGS</CODE> makefile options: <BLOCKQUOTE><CODE> <PRE> CFLAGS = -nostdinc -I/usr/i486-linuxlibc5/include -I/usr/lib/gcc-lib/i486-linuxlibc5/2.7.2.2/include -b i486-linuxlibc5 LDFLAGS = -b i486-linuxlibc5 </PRE> </CODE></BLOCKQUOTE> If you are using a configure script, define the <CODE>$CFLAGS</CODE> and <CODE>$LDFLAGS</CODE> shell variables (by using env/setenv for csh/tcsh, or set/export for sh/bash/etc) before running configure. The makefiles generated by this should contain the proper <CODE>$CFLAGS</CODE> and <CODE>$LDFLAGS</CODE>. Not all configure scripts will pick up the variables, so you should check after running configure and edit the makefiles by hand if necessary. <P>If the programs you are compiling only call gcc (and not cpp or binutils directly), you can use the following script to save having to specify all of the options each time: <BLOCKQUOTE><CODE> <PRE> #!/bin/bash /usr/bin/gcc -b i486-linuxlibc5 -nostdinc \ -I/usr/i486-linuxlibc5/include \ -I/usr/lib/gcc-lib/i486-linuxlibc5/2.7.2.2/include "$@" </PRE> </CODE></BLOCKQUOTE> You can then use this script instead of "gcc" when compiling. <P> <P> <HR> <A HREF="Glibc2-HOWTO-7.html">Next</A> <A HREF="Glibc2-HOWTO-5.html">Previous</A> <A HREF="Glibc2-HOWTO.html#toc6">Contents</A> </BODY> </HTML>