0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Building glibc on Linux(RHEL7.9)

Last updated at Posted at 2024-06-20

glibc をビルドしてみたので、記録として残す。
ビルド環境は Red Hat Enterprise Linux 7.9 です。

ソースコードをダウンロード

GNUのサイトからソース一式をダウンロードします。

Download にあるGNU ftp serverへのリンクをクリックすると、各バージョンの tar.gz がダウンロードできます。
今回はglibc-2.14.tar.gzをダウンロードしました。

Shell
wget https://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz

ダウンロードしたら任意の場所に展開します。

Shell
tar zxvf glibc-2.14.tar.gz

ビルド実行の前に(こんなエラーがでるよというお話)

ソースを展開すると、ビルド方法がINSTALLに記載されていますので詳細は確認しましょう。

当環境はもともと yum groupinstall で開発ツール (development)等をインストール済みです。

ビルド手順はconfigureコマンドを実行後にmakemake installコマンド実行を経て完了します。

ビルド用ディレクトリを作る

ビルドを実行するためには事前にconfigureコマンドを実行してMakefileなどを生成する必要がありますが、tarを展開した場所で直接./configureを実行するとエラーになります。

Shell
# ./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コマンドを実行する必要があります。作る場所はどこでもいいですし、ディレクトリ名もなんでもいいです。

Shell
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 などを生成するためのプログラムを実行します。

こんな感じでした。

Shell
# ../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分くらい)。

Shell
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配下に共有ライブラリやヘッダファイルが生成されます。

Shell
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は不要なので削除しても構いません。

良かった良かった。

参考にさせていただいたサイト。

以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?