カテゴリ
リンク

当サイトは、玄箱PRO (KURO-BOX/Pro)を中心とした組み込み、Linuxと電子工作を扱っています。
会社案内

情報セキュリティおよび個人情報の取り扱いについて


コメントとトラックバックは、spamを予防するために、編集担当が公開の作業をするまで非公開になっています。コメントはそれぞれ投稿した人のものです。

■どうしてスタティック・リンクのバイナリ?
  通常の Linux の実行ファイルは、ダイナミック・リンクで構成されています。C などで書かれたプログラムは、標準関数などライブラリに入っている関数を多く利用しています。そういったライブラリを、コンパイル時にプログラムと結合するのがスタティック・リンク、実行時に結合するのがダイナミック・リンクです。
  ダイナミック・リンクの場合には、実行時に必要なライブラリがないといけません。ここで使う tar は、Debian etch でコンパイルしますが、実行は玄箱PROのフラッシュ起動環境です。そのため、必要なライブラリ・ファイルがなく、実行できません。ライブラリをコピーする方法もありますが、ここではスタティック・リンクとします。
■tar をコンパイルする
 
 一度 Debian 環境で標準的な条件でコンパイルしてから、スタティック・リンクされた tar を作成します。まずは、dpkg を作成するためのツールをインストールします。 dpkg-dev と fakeroot です。root で以下を実行します。
apt-get install dpkg-dev fakeroot
 以下のようになりました。
kurobox@kurobox:~$ su 
Password: 
kurobox:/home/kurobox# apt-get install dpkg-dev fakeroot 
Reading package lists... Done 
Building dependency tree... Done 
The following extra packages will be installed: 
perl perl-modules 
Suggested packages: 
debian-keyring libterm-readline-gnu-perl libterm-readline-perl-perl 
Recommended packages: 
bzip2 perl-doc 
The following NEW packages will be installed: 
dpkg-dev fakeroot perl perl-modules 
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. 
Need to get 5972kB of archives. 
After unpacking 25.0MB of additional disk space will be used. 
Do you want to continue [Y/n]? 
Get:1 http://ftp.jp.debian.org etch/main perl-modules 5.8.8-7 [2310kB] 
Get:2 http://ftp.jp.debian.org etch/main perl 5.8.8-7 [3413kB] 
Get:3 http://ftp.jp.debian.org etch/main dpkg-dev 1.13.25 [166kB] 
Get:4 http://ftp.jp.debian.org etch/main fakeroot 1.5.10 [83.8kB] 
Fetched 5972kB in 5s (1138kB/s) 
Selecting previously deselected package perl-modules. 
(Reading database ... 9800 files and directories currently installed.) 
Unpacking perl-modules (from .../perl-modules_5.8.8-7_all.deb) ... 
Selecting previously deselected package perl. 
Unpacking perl (from .../archives/perl_5.8.8-7_arm.deb) ... 
Selecting previously deselected package dpkg-dev. 
Unpacking dpkg-dev (from .../dpkg-dev_1.13.25_all.deb) ... 
Selecting previously deselected package fakeroot. 
Unpacking fakeroot (from .../fakeroot_1.5.10_arm.deb) ... 
Setting up fakeroot (1.5.10) ... 

Setting up perl-modules (5.8.8-7) ... 
Setting up perl (5.8.8-7) ... 

Setting up dpkg-dev (1.13.25) ... 
kurobox:/home/kurobox#
 tar をコンパイルするのに必要なファイルをインストールします。
apt-get build-dep tar
 以下のようになります。
kurobox:/home/kurobox/# apt-get build-dep tar 
Reading package lists... Done 
Building dependency tree... Done 
The following NEW packages will be installed: 
autoconf autotools-dev build-essential debhelper file g++ g++-4.1 gettext 
gettext-base html2text intltool-debian libmagic1 libstdc++6-4.1-dev m4 
po-debconf 
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded. 
Need to get 7468kB of archives. 
After unpacking 25.4MB of additional disk space will be used. 
Do you want to continue [Y/n]? 
Get:1 http://ftp.jp.debian.org etch/main libmagic1 4.17-5etch1 [274kB] 
Get:2 http://ftp.jp.debian.org etch/main file 4.17-5etch1 [31.7kB] 
Get:3 http://ftp.jp.debian.org etch/main gettext-base 0.16.1-1 [121kB] 
Get:4 http://ftp.jp.debian.org etch/main m4 1.4.8-2 [178kB] 
Get:5 http://ftp.jp.debian.org etch/main autoconf 2.61-4 [448kB] 
Get:6 http://ftp.jp.debian.org etch/main autotools-dev 20060702.1 [60.6kB]
 -----------------------------------(省略)---------------------------
Setting up m4 (1.4.8-2) ... 

Setting up autoconf (2.61-4) ... 

Setting up autotools-dev (20060702.1) ... 
Setting up html2text (1.3.2a-3) ... 

Setting up gettext (0.16.1-1) ... 

Setting up intltool-debian (0.35.0+20060710.1) ... 
Setting up po-debconf (1.0.8) ... 
Setting up debhelper (5.0.42) ... 
Setting up libstdc++6-4.1-dev (4.1.1-21) ... 
Setting up g++-4.1 (4.1.1-21) ... 
Setting up g++ (4.1.1-15) ... 

Setting up build-essential (11.3) ... 
kurobox:/home/kurobox/#
 ここからの作業は、root の必要はありません。まず、tar を作成する作業用ディレクトリを作り、移動します。
mkdir work-tar cd work-tar
 ソース・ファイルを入手します。
apt-get source tar
 以下のようになりました。
kurobox@kurobox:~/work-tar$ apt-get source tar 
Reading package lists... Done 
Building dependency tree... Done 
Need to get 2231kB of source archives. 
Get:1 http://ftp.jp.debian.org etch/main tar 1.16-2 (dsc) [569B] 
Get:2 http://ftp.jp.debian.org etch/main tar 1.16-2 (tar) [2200kB] 
Get:3 http://ftp.jp.debian.org etch/main tar 1.16-2 (diff) [30.5kB] 
Fetched 2231kB in 1s (1209kB/s) 
gpg: can't open `/gnupg/options.skel': No such file or directory 
gpg: Signature made Sat Dec  2 01:41:31 2006 JST using DSA key ID F2CF01A8 
gpg: Can't check signature: public key not found 
dpkg-source: extracting tar in tar-1.16 
dpkg-source: unpacking tar_1.16.orig.tar.gz 
dpkg-source: applying ./tar_1.16-2.diff.gz 
kurobox@kurobox:~/work-tar$
ディレクトリを移動し、コンパイルします。
cd tar-1.16 dpkg-buildpackage -rfakeroot -us -uc
 以下のようになりました。
kurobox@kurobox:~/work-tar$ cd tar-1.16/ 
kurobox@kurobox:~/work-tar/tar-1.16$ dpkg-buildpackage -rfakeroot -us -uc 
dpkg-buildpackage: source package is tar 
dpkg-buildpackage: source version is 1.16-2 
dpkg-buildpackage: source changed by Bdale Garbee <bdale@gag.com> 
dpkg-buildpackage: host architecture arm 
dpkg-buildpackage: source version without epoch 1.16-2 
fakeroot debian/rules clean 
dh_testdir 
dh_testroot 
rm -f build-stamp configure-stamp 
/usr/bin/make distclean 
make[1]: Entering directory `/home/kurobox/work-tar/tar-1.16'
-----------------------------------(省略)---------------------------
dh_compress 
dh_fixperms 
dh_installdeb 
dh_shlibdeps 
dh_gencontrol 
dh_md5sums 
dh_builddeb 
dpkg-deb: building package `tar' in `../tar_1.16-2_arm.deb'. 
dpkg-genchanges 
dpkg-genchanges: not including original source code in upload 
dpkg-buildpackage: binary and diff upload (original source NOT included) 
kurobox@kurobox:~/work-tar/tar-1.16$
 src ディレクトリに移動し、
cd src
 Makefile を編集し、LDFLAGS を -static にします。
INTLLIBS = INTL_MACOSX_LIBS = INTTYPES_H = inttypes.h LDFLAGS = -static LIBICONV = LIBINTL =
 一度 tar を消し、再度 tar を生成します。最後に strip で実行時に不要なシンボルや関数を削除し、ファイル・サイズを小さくします。
rm tar make strip tar
 実行すると以下のようになりました。
kurobox:/home/kurobox/work-tar/tar-1.16/src# rm tar 
kurobox:/home/kurobox/work-tar/tar-1.16/src# make 
gcc  -O2 -g -Wall  -static -o tar  buffer.o compare.o create.o delete.o extract.o xheader.o incremen.o list.o mangle.o misc.o names.o sparse.o system.o tar.o transform.o update.o utf8.o ../lib/libtar.a   -lrt 
names.o: In function `gid_to_gname': 
/home/kurobox/work-tar/tar-1.16/src/names.c:105: warning: Using 'getgrgid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
names.o: In function `gname_to_gid': 
/home/kurobox/work-tar/tar-1.16/src/names.c:165: warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
names.o: In function `uname_to_uid': 
/home/kurobox/work-tar/tar-1.16/src/names.c:135: warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
names.o: In function `uid_to_uname': 
/home/kurobox/work-tar/tar-1.16/src/names.c:75: warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
kurobox:/home/kurobox/work-tar/tar-1.16/src# strip tar 
kurobox:/home/kurobox/work-tar/tar-1.16/src#
 これで、スタティック・リンクの tar ができました。

 カテゴリ 

 

トラックバック(0)

このブログ記事を参照しているブログ一覧: スタティック・リンクの tar の作成

このブログ記事に対するトラックバックURL: http://www.eleki-jack.com/mt/mt-tb.cgi/940

コメントする

おすすめ書籍
Powered by
Movable Type 4.1