📄 如何为嵌入式开发建立交叉编译环境.htm
字号:
<TD class=code-outline><PRE class=displaycode>$cd $PRJROOT/build-tools
$tar -xvzf glibc-2.2.3.tar.gz
$tar -xzvf glibc-linuxthreads-2.2.3.tar.gz --directory=glibc-2.2.3
</PRE></TD></TR></TBODY></TABLE><BR>
<P>然后进入 build-glibc 目录配置 glibc</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=code-outline><PRE class=displaycode>$cd build-glibc
$CC=arm-linux-gcc ../glibc-2.2.3/configure --host=$TARGET --prefix="/usr"
--enable-add-ons --with-headers=$TARGET_PREFIX/include
</PRE></TD></TR></TBODY></TABLE><BR>
<P>CC=arm-linux-gcc 是把 CC 变量设成你刚编译完的boostrap
gcc,用它来编译你的glibc。--enable-add-ons是告诉glibc用 linuxthreads
包,在上面我们已经将它放入了 glibc 源码目录中,这个选项等价于
-enable-add-ons=linuxthreads。--with-headers 告诉 glibc 我们的linux
内核头文件的目录位置。</P>
<P>配置完后就可以编译和安装 glibc</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=code-outline><PRE class=displaycode>$make
$make install_root=$TARGET_PREFIX prefix="" install
</PRE></TD></TR></TBODY></TABLE><BR>
<P>然后你还要修改 libc.so 文件</P>
<P>将<BR>GROUP ( /lib/libc.so.6 /lib/libc_nonshared.a)</P>
<P>改为<BR>GROUP ( libc.so.6 libc_nonshared.a)</P>
<P>这样连接程序 ld 就会在 libc.so
所在的目录查找它需要的库,因为你的机子的/lib目录可能已经装了一个相同名字的库,一个为编译可以在你的宿主机上运行的程序的库,而不是用于交叉编译的。</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt=""
src="如何为嵌入式开发建立交叉编译环境.files/blue_rule.gif"
width="100%"><BR><IMG height=6 alt=""
src="如何为嵌入式开发建立交叉编译环境.files/c.gif" width=8
border=0></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD><IMG height=4 alt="" src="如何为嵌入式开发建立交叉编译环境.files/c.gif"
width="100%"><BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt=""
src="如何为嵌入式开发建立交叉编译环境.files/u_bold.gif" width=16
border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox
href="http://www.ibm.com/developerworks/cn/linux/l-embcmpl/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=N102C0><SPAN class=atitle>建立全套编译器(full
gcc)</SPAN></A></P>
<P>在建立boot-gcc 的时候,我们只支持了C。到这里,我们就要建立全套编译器,来支持C和C++。</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=code-outline><PRE class=displaycode>$cd $PRJROOT/build-tools/build-gcc
$../gcc-2.95.3/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++
</PRE></TD></TR></TBODY></TABLE><BR>
<P>--enable-languages=c,c++ 告诉 full gcc 支持 c 和 c++ 语言。</P>
<P>然后编译和安装你的 full gcc</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=code-outline><PRE class=displaycode>$make all
$make install
</PRE></TD></TR></TBODY></TABLE><BR>
<P>我们再来看看 $PREFIX/bin 里面多了哪些东西</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=code-outline><PRE class=displaycode>$ls $PREFIX/bin
</PRE></TD></TR></TBODY></TABLE><BR>
<P>你会发现多了 arm-linux-g++ 、arm-linux-protoize 和 arm-linux-c++
几个文件。</P>
<P>G++-gnu的 c++ 编译器。</P>
<P>Protoize-与Unprotoize相反,将K&R C的源码转化为ANSI C的形式,函数原型中加入参数类型。</P>
<P>C++-gnu 的 c++ 编译器。</P>
<P>到这里你的交叉编译工具就算做完了,简单验证一下你的交叉编译工具。</P>
<P>用它来编译一个很简单的程序 helloworld.c</P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=code-outline><PRE class=displaycode>#include <stdio.h>
int main(void)
{
printf("hello world\n");
return 0;
}
$arm-linux-gcc helloworld.c -o helloworld
$file helloworld
helloworld: ELF 32-bit LSB executable, ARM, version 1,
dynamically linked (uses shared libs), not stripped
</PRE></TD></TR></TBODY></TABLE><BR>
<P>上面的输出说明你编译了一个能在 arm 体系结构下运行的 helloworld,证明你的编译工具做成功了。</P><BR><BR>
<P><A name=resources><SPAN class=atitle>参考资料 </SPAN></A></P>
<UL>
<LI>Wookey ,Chris Rutter, Jeff Sutherland, Paul Webb ,《The GNU
Toolchain for ARM Target HOWTO》<BR><BR>
<LI>Karim Yaghmour,《Building Embedded Linux
Systems》,USA:O'Reilly,2003<BR></LI></UL><BR><BR>
<P><A name=author><SPAN class=atitle>关于作者</SPAN></A></P>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD colSpan=3><IMG height=5 alt=""
src="如何为嵌入式开发建立交叉编译环境.files/c.gif" width="100%"></TD></TR>
<TR vAlign=top align=left>
<TD>
<P></P></TD>
<TD><IMG height=5 alt="" src="如何为嵌入式开发建立交叉编译环境.files/c.gif"
width=4></TD>
<TD width="100%">
<P>梁元恩,软件工程师,研究兴趣主要是操作系统,图形学等。您可以通过<A
href="mailto:sunix_yuanenliang@yahoo.com.cn">sunix_yuanenliang@yahoo.com.cn</A>联系他。</P></TD></TR></TBODY></TABLE><BR><BR><BR>
<P class=no-print><SPAN class=atitle><A
name=rate>对本文的评价</A></SPAN></P><SPAN class=no-print>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD>
<FORM
action=https://www.ibm.com/developerworks/secure/cnratings.jsp
method=get><INPUT type=hidden value=如何为嵌入式开发建立交叉编译环境
name=ArticleTitle><INPUT type=hidden value=Linux
name=Zone><INPUT type=hidden
value=http://www.ibm.com/developerworks/cn/thankyou/
name=RedirectURL><INPUT type=hidden value=china
name=localsite>
<SCRIPT language=javascript>document.write('<input type="hidden" name="url" value="'+location.href+'" />');</SCRIPT>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG height=8 alt=""
src="如何为嵌入式开发建立交叉编译环境.files/c.gif" width=100
border=0></TD></TR>
<TR vAlign=top>
<TD><INPUT type=radio value=1 name=Rating>太差! (1)</TD></TR>
<TR vAlign=top>
<TD><INPUT type=radio value=2 name=Rating>需提高 (2)</TD></TR>
<TR vAlign=top>
<TD><INPUT type=radio value=3 name=Rating>一般;尚可
(3)</TD></TR>
<TR vAlign=top>
<TD><INPUT type=radio value=4 name=Rating>好文章 (4)</TD></TR>
<TR vAlign=top>
<TD><INPUT type=radio value=5
name=Rating>真棒!(5)</TD></TR></TBODY></TABLE><BR><B>建议?</B><BR><TEXTAREA id=Comments name=Comments rows=5 wrap=virtual cols=60> </TEXTAREA><BR><BR><INPUT type=submit value=反馈意见></FORM></TD></TR>
<TR vAlign=top>
<TD bgColor=#ffffff><IMG height=8 alt=""
src="如何为嵌入式开发建立交叉编译环境.files/c.gif" width=100
border=0></TD></TR></TBODY></TABLE></SPAN><SPAN class=no-print>
<TABLE cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD><IMG height=8 alt="" src="如何为嵌入式开发建立交叉编译环境.files/c.gif"
width="100%"><BR>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt=""
src="如何为嵌入式开发建立交叉编译环境.files/u_bold.gif" width=16
border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox
href="http://www.ibm.com/developerworks/cn/linux/l-embcmpl/#main"><B>回页首</B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR></SPAN></TD>
<TD width=10><IMG height=1 alt="" src="如何为嵌入式开发建立交叉编译环境.files/c.gif"
width=10></TD></TR></TBODY></TABLE><SPAN class=small>IBM 公司保留在
developerWorks 网站上发表的内容的著作权。未经IBM公司或原始作者的书面明确许可,请勿转载。如果您希望转载,请通过 <A
href="https://www.ibm.com/developerworks/secure/reprintreq.jsp?domain=dwchina">提交转载请求表单</A>
联系我们的编辑团队。</SPAN></TD></TR></TBODY></TABLE><!--FOOTER_BEGIN--><!-- IBM FOOTER -->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=bbg height=19>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><SPAN class=spacer> </SPAN><A
class=mainlink href="http://www.ibm.com/cn/ibm/index.shtml">关于
IBM</A></TD>
<TD class=footer-divider width=27> </TD>
<TD><A class=mainlink
href="http://www.ibm.com/cn/ibm/privacy/index.shtml">隐私条约</A></TD>
<TD class=footer-divider width=27> </TD>
<TD><A class=mainlink href="http://www.ibm.com/contact/cn/">联系
IBM</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!-- end footer -->
<SCRIPT language=JavaScript1.2 src="如何为嵌入式开发建立交叉编译环境.files/stats.js"
type=text/javascript></SCRIPT>
<NOSCRIPT><IMG height=1 alt=""
src="D:\李晓宁\教学\上课PPT\如何为嵌入式开发建立交叉编译环境.files\c(1).gif" width=1
border=0></NOSCRIPT><!--FOOTER_END--><!--XSLT stylesheet used to transform this file: dw-document-html-5.8.xsl--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -