⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 如何为嵌入式开发建立交叉编译环境 wimax宽带无线网络技术论坛 - www_wimax_org_cn.htm

📁 再做嵌入式开发的时候
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<FONT face="Lucida Console">$cd build-binutils
$../binutils-2.10.1/configure --target=$TARGET --prefix=$PREFIX
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>--target 选项是指出我们生成的是 arm-linux 的工具,--prefix 
                        是指出我们可执行文件安装的位置。</P>
                        <P>会出现很多 check,最后产生 Makefile 文件。</P>
                        <P>有了 Makefile 后,我们来编译并安装 binutils,命令很简单。</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$make
$make install
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>看一下我们 $PREFIX/bin 下的生成的文件</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$ls $PREFIX/bin
arm-linux-addr2line	arm-linux-gasp	arm-linux-objdump		arm-linux-strings
arm-linux-ar			arm-linux-ld		arm-linux-ranlib		arm-linux-strip
arm-linux-as			arm-linux-nm		arm-linux-readelf	
arm-linux-c++filt		arm-linux-objcopy	arm-linux-size
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>我们来解释一下上面生成的可执行文件都是用来干什么的</P>
                        <P>add2line - 将你要找的地址转成文件和行号,它要使用 debug 信息。</P>
                        <P>Ar-产生、修改和解开一个存档文件</P>
                        <P>As-gnu 的汇编器</P>
                        <P>C++filt-C++ 和 java 
                        中有一种重载函数,所用的重载函数最后会被编译转化成汇编的标号,c++filt 
                        就是实现这种反向的转化,根据标号得到函数名。</P>
                        <P>Gasp-gnu 汇编器预编译器。</P>
                        <P>Ld-gnu 的连接器</P>
                        <P>Nm-列出目标文件的符号和对应的地址</P>
                        <P>Objcopy-将某种格式的目标文件转化成另外格式的目标文件</P>
                        <P>Objdump-显示目标文件的信息</P>
                        <P>Ranlib-为一个存档文件产生一个索引,并将这个索引存入存档文件中</P>
                        <P>Readelf-显示 elf 格式的目标文件的信息</P>
                        <P>Size-显示目标文件各个节的大小和目标文件的大小</P>
                        <P>Strings-打印出目标文件中可以打印的字符串,有个默认的长度,为4</P>
                        <P>Strip-剥掉目标文件的所有的符号信息</P><BR>
                        <TABLE cellSpacing=0 cellPadding=0 width="100%" 
border=0>
                          <TBODY>
                          <TR>
                            <TD><IMG height=1 alt="" src="" 
                              width="100%"><BR><IMG height=6 alt="" src="" 
                              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="" width="100%"><BR>
                              <TABLE cellSpacing=0 cellPadding=0 border=0>
                                <TBODY>
                                <TR>
                                <TD vAlign=center><IMG height=16 alt="" src="" 
                                width=16 border=0><BR></TD>
                                <TD vAlign=top align=right><A class=fbox 
                                href="http://www-128.ibm.com/developerworks/cn/linux/l-embcmpl/#main"><B><FONT 
                                color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
                        <P><A name=N10200><SPAN class=atitle><FONT face=Arial 
                        size=4>建立初始编译器(bootstrap gcc)</FONT></SPAN></A></P>
                        <P>首先进入 build-tools 目录,将下载 gcc 源代码解压</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd $PRJROOT/build-tools
$tar -xvzf  gcc-2.95.3.tar.gz
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>然后进入 gcc-2.95.3 目录给 gcc 打上补丁</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd gcc-2.95.3
$patch -p1&lt; ../gcc-patch/gcc-2.95.3.-2.patch
$patch -p1&lt; ../gcc-patch/gcc-2.95.3.-no-fixinc.patch
$patch -p1&lt; ../gcc-patch/gcc-2.95.3-returntype-fix.patch
echo timestamp &gt; gcc/cstamp-h.in
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>在我们编译并安装 gcc 前,我们先要改一个文件 
                        $PRJROOT/gcc/config/arm/t-linux,把<BR>TARGET_LIBGCC2-CFLAGS 
                        = -fomit-frame-pointer 
                        -fPIC<BR>这一行改为<BR>TARGET_LIBGCC2-CFLAGS = 
                        -fomit-frame-pointer -fPIC -Dinhibit_libc 
                        -D__gthr_posix_h</P>
                        <P>你如果没定义 -Dinhibit,编译时将会报如下的错误</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">../../gcc-2.95.3/gcc/libgcc2.c:41: stdlib.h: No such file or directory
../../gcc-2.95.3/gcc/libgcc2.c:42: unistd.h: No such file or directory
make[3]: *** [libgcc2.a] Error 1
make[2]: *** [stmp-multilib-sub] Error 2
make[1]: *** [stmp-multilib] Error 1
make: *** [all-gcc] Error 2
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>如果没有定义 -D__gthr_posix_h,编译时会报如下的错误</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">In file included from gthr-default.h:1,
                 from ../../gcc-2.95.3/gcc/gthr.h:98,
                 from ../../gcc-2.95.3/gcc/libgcc2.c:3034:
../../gcc-2.95.3/gcc/gthr-posix.h:37: pthread.h: No such file or directory
make[3]: *** [libgcc2.a] Error 1
make[2]: *** [stmp-multilib-sub] Error 2
make[1]: *** [stmp-multilib] Error 1
make: *** [all-gcc] Error 2
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>还有一种与-Dinhibit同等效果的方法,那就是在你配置configure时多加一个参数-with-newlib,这个选项不会迫使我们必须使用newlib。我们编译了bootstrap-gcc后,仍然可以选择任何c库。</P>
                        <P>接着就是配置boostrap gcc, 后面要用bootstrap gcc 来编译 glibc 
                        库。</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd ..; cd build-boot-gcc
$../gcc-2.95.3/configure --target=$TARGET --prefix=$PREFIX \
&gt;--without-headers  --enable-languages=c --disable-threads
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>这条命令中的 -target、--prefix 和配置 binutils 
                        的含义是相同的,--without-headers 
                        就是指不需要头文件,因为是交叉编译工具,不需要本机上的头文件。-enable-languages=c是指我们的 
                        boot-gcc 只支持 c 语言。--disable-threads 是去掉 thread 功能,这个功能需要 
                        glibc 的支持。</P>
                        <P>接着我们编译并安装 boot-gcc</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$make all-gcc
$make install-gcc
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>我们来看看 $PREFIX/bin 里面多了哪些东西</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$ls $PREFIX/bin
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>你会发现多了 arm-linux-gcc 、arm-linux-unprotoize、cpp 和 gcov 
                        几个文件。</P>
                        <P>Gcc-gnu 的 C 语言编译器</P>
                        <P>Unprotoize-将 ANSI C 的源码转化为 K&amp;R C 
                        的形式,去掉函数原型中的参数类型。</P>
                        <P>Cpp-gnu的 C 的预编译器</P>
                        <P>Gcov-gcc 的辅助测试工具,可以用它来分析和优程序。</P>
                        <P>使用 gcc3.2 以及 gcc3.2 以上版本时,配置 boot-gcc 不能使用 
                        --without-headers 选项,而需要使用 glibc 的头文件。</P><BR>
                        <TABLE cellSpacing=0 cellPadding=0 width="100%" 
border=0>
                          <TBODY>
                          <TR>
                            <TD><IMG height=1 alt="" src="" 
                              width="100%"><BR><IMG height=6 alt="" src="" 
                              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="" width="100%"><BR>
                              <TABLE cellSpacing=0 cellPadding=0 border=0>
                                <TBODY>
                                <TR>
                                <TD vAlign=center><IMG height=16 alt="" src="" 
                                width=16 border=0><BR></TD>
                                <TD vAlign=top align=right><A class=fbox 
                                href="http://www-128.ibm.com/developerworks/cn/linux/l-embcmpl/#main"><B><FONT 
                                color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
                        <P><A name=N1027B><SPAN class=atitle><FONT face=Arial 
                        size=4>建立 c 库(glibc)</FONT></SPAN></A></P>
                        <P>首先解压 glibc-2.2.3.tar.gz 和 
                        glibc-linuxthreads-2.2.3.tar.gz 源代码</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$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
</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
                        <P>然后进入 build-glibc 目录配置 glibc</P><BR>
                        <TABLE cellSpacing=0 cellPadding=5 width="100%" 
                        bgColor=#eeeeee border=1>
                          <TBODY>
                          <TR>
                            <TD><PRE><CODE class=section>
<FONT face="Lucida Console">$cd build-glibc
$CC=arm-linux-gcc ../glibc-2.2.3/configure --host=$TARGET --prefix="/usr" 
--enable-add-ons --with-headers=$TARGET_PREFIX/include
</FONT></CODE></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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -