避免cross-compile的陷阱:libtool [转]

避免cross-compile的陷阱:libtool http://orzlab.blogspot.com/2007/05/cross-compilelibtool.html

�嘶`: cross development, openembedded

在Unix系�y上,有��知名的 "make" 工具,可�f助�_�l程式,但是�S著程式�_�l�}�s度的提�N,已�很�y用有限的 "make rules" ��M足多�的需求,所以Cygnus/RedHat的Tom Tromey就�O�autoconf�cautomake等工具,期望大幅降低���|性平台�_�l的困�y。�@也包含所�^的cross-compile,�榱丝朔�不同平台的函式�炀��g落差, libtool也被提出,立意甚好但往往�我��遇到不少���},比方�f知名的hacker - Casey Marshall - 就在�c�@些上�f行的工具程式�^�鹨欢�r�g後,��了篇短文 "Avoiding libtool minefields when cross-compiling"。autoconf�cautomake等工具最核心的想法就是希望��g�^程可以�化成如下: (以x86下�M行ARM-Linux程式��g�槔�)

./configure --host=arm-linux \
--prefix=/usr \
--enable-shared \
--enable-Feature1 \
--disable-Feature2
�P者�⑴c的若干自由��w���中,也��m��入此�O�,如上的�M�B所示,我��指定cross-compile的�ο��arm-linux, automake��依��特定�l件去找�づc�y���g�h境,同�r我���⒂�Feature1�c抑制Feature2,接著一堆上�f行的Makefile就��乖乖建��了。那�N,���}在哪呢?我��很常�到以下的��g�e�`:
/bin/sh libtool --mode=link target-gcc -c -O2 -o libbar.so ... -lfoo
target-gcc -c -O2 -o libbar.so ... /usr/lib/libfoo.so
/usr/lib/libfoo.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status很明�@, libtool被�`�В�原本��ふ�arch = arm的程式�n案,�]想到抓到host (x86)上的�n案,�楹稳绱耍课���S便挑一��描述程式�B�Y�Y�的*.la�n案:
$ cat /usr/lib/libesd.la
# libesd.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.5.6 (1.1220.2.95 2004/04/11 05:50:42) Debian: 224 $
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libesd.so.0'

# Names of this library.
library_names='libesd.so.0.2.36 libesd.so.0 libesd.so'

# The name of the static archive.
old_library='libesd.a'

# Libraries that this one depends upon.
dependency_libs=' -L/usr/lib /usr/lib/libaudiofile.la -lm'

# Version information for libesd.
current=2
age=2
revision=36

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/lib'再清楚不�^,�@肇因於��libdir指向Host/x86上的目�下,但�@些*.la�n案已�置放於 "staging" (工作�^),於是我��可用GNU sed去更�印1确秸f "staging" 目�於 /tmp/rootfs,那�N:
sed -i~ -e "s;/usr;/tmp/rootfs/usr;"
�@之�g有�H多繁��的工作,�好 OpenEmbedded�� autoconf、 automake,�c libtool作了修正,所以大部分的Automake-based applications可以很容易透�^ OpenEmbedded去建��,但副作用�t是需要re-generated,又,�@�拥奶准�或��用程式往往�锥�担�耗�M的�r�g也相��可�^。

你可能感兴趣的:(#嵌入式linux)