glibc をビルドしてみたので、記録として残す。
ビルド環境は Red Hat Enterprise Linux 7.9 です。
ソースコードをダウンロード
GNUのサイトからソース一式をダウンロードします。
Download にあるGNU ftp server
へのリンクをクリックすると、各バージョンの tar.gz がダウンロードできます。
今回はglibc-2.14.tar.gz
をダウンロードしました。
wget https://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz
ダウンロードしたら任意の場所に展開します。
tar zxvf glibc-2.14.tar.gz
ビルド実行の前に(こんなエラーがでるよというお話)
ソースを展開すると、ビルド方法がINSTALL
に記載されていますので詳細は確認しましょう。
当環境はもともと yum groupinstall で開発ツール (development)
等をインストール済みです。
ビルド手順はconfigure
コマンドを実行後にmake
とmake install
コマンド実行を経て完了します。
ビルド用ディレクトリを作る
ビルドを実行するためには事前にconfigure
コマンドを実行してMakefileなどを生成する必要がありますが、tarを展開した場所で直接./configure
を実行するとエラーになります。
# ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
configure: error: you must configure in a separate build directory
なので、別の場所にビルド用の一時ディレクトリを作って、そこからconfigure
コマンドを実行する必要があります。作る場所はどこでもいいですし、ディレクトリ名もなんでもいいです。
mkdir ../glibc-build
glibcのインストール先を指定
./configure
実行時に--prefix
オプションを指定していない場合はエラーになります。
# cd glibc-build
# ../glibc-2.14/configure
*** On GNU/Linux systems the GNU C Library should not be installed into
*** /usr/local since this might make your system totally unusable.
*** We strongly advise to use a different prefix. For details read the FAQ.
*** If you really mean to do this, run configure again using the extra
*** parameter `--disable-sanity-checks'.
これはデフォルトで--prefix=/usr/local
が指定されたものとして実行されるが、このディレクトリにビルドしたライブラリをインストールするとシステムが壊れる可能性があるからお勧めしないというような内容である。
この警告を無視する場合は--disable-sanity-checks
オプションを付けてconfigure
を実行するとよい。警告に従う場合は--prefix=<パス>
でインストールしたい場所を指定します。
この手順ではインストール先に/opt/glibc-2.14
を指定するものとして進めます。
つまり、オプションは--prefix=/opt/glibc-2.14
と指定します。
ビルドの実行
実際のビルドの様子です。
ビルドの準備./configure
の実行
ビルドの前に Makefile などを生成するためのプログラムを実行します。
こんな感じでした。
# ../glibc-2.14/configure --prefix=/opt/glibc-2.14
・・・
checking whether -fPIC is default... no
configure: creating ./config.status
config.status: creating config.make
config.status: creating Makefile
config.status: creating config.h
config.status: executing default commands
./configure
に成功すると、Makefileなどがglibc-build
ディレクトリに作成されるのでビルドできる状態になる。
make
の実行
こんな感じでした。
実行完了までにはしばらく時間がかかりました(10分くらい)。
cd glibc-build
make
・・・
gcc -nostdlib -nostartfiles -static -o /root/glibc-build/elf/ldconfig /root/glibc-build/csu/crt1.o /root/glibc-build/csu/crti.o `gcc --print-file-name=crtbegin.o` /root/glibc-build/elf/ldconfig.o /root/glibc-build/elf/cache.o /root/glibc-build/elf/readlib.o /root/glibc-build/elf/xmalloc.o /root/glibc-build/elf/xstrdup.o /root/glibc-build/elf/chroot_canon.o -Wl,--start-group /root/glibc-build/libc.a -lgcc -lgcc_eh -Wl,--end-group `gcc --print-file-name=crtend.o` /root/glibc-build/csu/crtn.o
make[2]: ディレクトリ `/root/glibc-2.14/elf' から出ます
make[1]: ディレクトリ `/root/glibc-2.14' から出ます
成功したのかどうかが分からなかったのですが、終了コードecho $?
が 0 だったので成功したのでしょう。
この段階ではまだ/opt/glibc-2.14
配下には何もありません。
make install
の実行
こんな感じでした。
成功すると--prefix
で指定した/opt/glibc-2.14
配下に共有ライブラリやヘッダファイルが生成されます。
cd glibc-build
make install
LANGUAGE=C LC_ALL=C; export LANGUAGE LC_ALL; \
make -r PARALLELMFLAGS="" CVSOPTS="" -C ../glibc-2.14 objdir=`pwd` install
make[1]: Entering directory `/root/glibc-2.14'
・・・
test ! -x /root/glibc-build/elf/ldconfig || LC_ALL=C LANGUAGE=C \
/root/glibc-build/elf/ldconfig \
/opt/glibc-2.14/lib /opt/glibc-2.14/lib
/root/glibc-build/elf/ldconfig: Can't open configuration file /opt/glibc-2.14/etc/ld.so.conf: No such file or directory
make[1]: Leaving directory `/root/glibc-2.14'
こんな感じにね。
# ll /opt/glibc-2.14/
合計 16
drwxr-xr-x 2 root root 228 6月 20 19:58 bin
drwxr-xr-x 2 root root 53 6月 20 19:58 etc
drwxr-xr-x 22 root root 4096 6月 20 19:58 include
drwxr-xr-x 4 root root 4096 6月 20 19:58 lib
drwxr-xr-x 3 root root 37 6月 20 19:58 libexec
drwxr-xr-x 2 root root 88 6月 20 19:58 sbin
drwxr-xr-x 5 root root 48 6月 20 18:33 share
ここまで終わったらビルド用ディレクトリglibc-build
は不要なので削除しても構いません。
良かった良かった。
参考にさせていただいたサイト。
以上です。