다음 이전 차례

6. non-primary libc로 컴파일하기

프로그램을 컴파일 하다 보면, 다른 라이브러리를 사용하고 싶은 때가 있을 것이다. 이 단원에서는 어떻게 하면 다른 라이브러리를 사용할 수 있는가를 설명한다. 우선 기억해야 할 것은 앞의 두 단원에서 예로 사용되었던 디렉토리 이름과 설치 이름을 사용한다는 것이다. Remember to change the names to fit your setup.

6.1 non-primary libcs 사용할 때 경고

시스템 부팅 과정에 사용되는 프로그램을 컴파일 할 때 기억할 것은, 그 프로그램을 동적으로 링크하고 non-root 파티션이 마운트되기 이전에 사용한다면, 모든 링크되는 라이브러리는 root 파티션에 있어야만 한다는 것이다. glibc를 주 C 라이브러리로 설치하는 과정(앞 단원)을 했다면, 구 libc는 /lib에 있다. /lib는 root 파티션에 있어야한다. 이것은 아직도 모든 당신 프로그램이 부팅하는 동안에는 작동한다는 것이다. 그러나, 만약 /usr이 다른 파티션에 있고, glibc를 /usr/i486-linuxglibc2에 연습용으로 설치했다면, glibc와 함께 컴파일된 프로그램들은 /usr 파티션이 마운트되기 이전까지는 작동하지 않는다는 것이다.

6.2 연습용 glibc와 함께 컴파일하기.

연습용 glibc와 함께 프로그램을 컴파일하기위해선 glibc include에 include path 를 다시 설정할 필요가 있다.

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 /usr/lib/gcc-lib/i486-linuxglibc2/2.7.2.2/include (assuming you installed the test lib in i486-linuxglibc2 with gcc version 2.7.2.2).

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".

For most programs, you can specify these new options by adding them to the CFLAGS and LDFLAGS makefile options:

 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
 
If you are using a configure script, define the CFLAGS and LDFLAGS 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 CFLAGS and LDFLAGS. Not all configure scripts will pick up the variables, so you should check after running configure and edit the makefiles by hand if necessary.

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:

 #!/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 "$@"
 
You can then use this script instead of "gcc" when compiling.

6.3 Compiling programs with libc 5 when glibc is primary library

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.

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".

For most programs, you can specify these new options by appending them to the CFLAGS and LDFLAGS makefile options:

 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
 
If you are using a configure script, define the CFLAGS and LDFLAGS 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 CFLAGS and LDFLAGS. Not all configure scripts will pick up the variables, so you should check after running configure and edit the makefiles by hand if necessary.

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:

 #!/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 "$@"
 
You can then use this script instead of "gcc" when compiling.


다음 이전 차례