制作交叉工具链(龙芯)

系统环境:ubuntu10.04 + gcc-4.3.3

所需软件:
Binutils 2.20: http://ftp.gnu.org/gnu/binutils/binutils-2.20.tar.bz2
GCC Core 4.4.2: http://ftp.gnu.org/gnu/gcc/gcc-4.4.2/gcc-core-4.4.2.tar.bz2 

Binutils 2.20 Loongson2f 补丁 binutils-2.20-loongson2f.zip   

设置环境变量和新建目录

$ mkdir -p /opt/loongson-cross-tools/usr/{bin, lib, share}

$ echo "PATH=$PATH:/opt/loongson-cross-tools/usr/bin" >> ~/.bashrc

编译 Binutils: 

$ tar xjf binutils-2.20.tar.bz2

$ cd binutils-2.20

$ patch -Np1 -i ../binutils-2.20-loongson2f.patch   //这步没做,没有找到patch

$ cd .. && mkdir binutils-build && cd binutils-build

$ ../binutils-2.20/configure --prefix=/opt/loongson-cross-tools/usr --target=mipsel-pc-linux-gnu --with-sysroot=/opt/loongson-cross-tools --enable-64-bit-bfd --disable-nls --enable-shared

$ make configure-host

$ make

$ make install

出错信息:

        rm -rf $backupdir; exit $rc

WARNING: `makeinfo' is missing on your system.  You should only need it if

         you modified a `.texi' or `.texinfo' file, or any other file

         indirectly affecting the aspect of the manual.  The spurious

         call might also be the consequence of using a buggy `make' (AIX,

         DU, IRIX).  You might want to install the `Texinfo' package or

         the `GNU make' package.  Grab either from any GNU archive site.

make[4]: *** [as.info] Error 1

make[4]: Leaving directory `/home/loongson/loongson-cross-tool/binutils-build/gas/doc'

make[3]: *** [install-am] Error 2

make[3]: Leaving directory `/home/loongson/loongson-cross-tool/binutils-build/gas/doc'

Making install in po

make[3]: Entering directory `/home/loongson/loongson-cross-tool/binutils-build/gas/po'

make[3]: Nothing to be done for `install'.

make[3]: Leaving directory `/home/loongson/loongson-cross-tool/binutils-build/gas/po'

make[3]: Entering directory `/home/loongson/loongson-cross-tool/binutils-build/gas'

make[4]: Entering directory `/home/loongson/loongson-cross-tool/binutils-build/gas'

/bin/bash ../../binutils-2.20/gas/../mkinstalldirs /opt/loongson-cross-tools/usr/bin

 /bin/bash ./libtool  --mode=install /usr/bin/install -c as-new /opt/loongson-cross-tools/usr/bin/mipsel-pc-linux-gnu-as

libtool: install: /usr/bin/install -c .libs/as-new /opt/loongson-cross-tools/usr/bin/mipsel-pc-linux-gnu-as

/bin/bash ../../binutils-2.20/gas/../mkinstalldirs /opt/loongson-cross-tools/usr/mipsel-pc-linux-gnu/bin

n=`echo as | sed 's&^&mipsel-pc-linux-gnu-&'`; \

        if [ "/opt/loongson-cross-tools/usr/bin/$n" != "/opt/loongson-cross-tools/usr/mipsel-pc-linux-gnu/bin/as" ]; then \

          rm -f /opt/loongson-cross-tools/usr/mipsel-pc-linux-gnu/bin/as; \

          ln /opt/loongson-cross-tools/usr/bin/$n /opt/loongson-cross-tools/usr/mipsel-pc-linux-gnu/bin/as >/dev/null 2>/dev/null \

            || /bin/bash ./libtool --mode=install /usr/bin/install -c as-new /opt/loongson-cross-tools/usr/mipsel-pc-linux-gnu/bin/as; \

        else \

          true ; \

        fi

make[4]: Nothing to be done for `install-data-am'.

make[4]: Leaving directory `/home/loongson/loongson-cross-tool/binutils-build/gas'

make[3]: Leaving directory `/home/loongson/loongson-cross-tool/binutils-build/gas'

make[2]: *** [install-recursive] Error 1

make[2]: Leaving directory `/home/loongson/loongson-cross-tool/binutils-build/gas'

make[1]: *** [install-gas] Error 2

make[1]: Leaving directory `/home/loongson/loongson-cross-tool/binutils-build'

make: *** [install] Error 2

参考解决办法:

原因是本机没有安装texinfo,安装之后版本也不够高,顾修改configure文件

$ sudo apt-get install texinfo

$ makeinfo --version

makeinfo (GNU texinfo) 4.13

$ vim ../binuitl-2.20/configure

改成:

$ make install

编译 GCC: 

$ tar xjf gcc-core-4.4.2.tar.bz2

$ mkdir gcc-build  && cd gcc-build

$ ../gcc-4.4.2/configure --prefix=/opt/loongson-cross-tools/usr --target=mipsel-pc-linux-gnu --with-sysroot=/opt/loongson-cross-tools --disable-multilib --with-newlib --disable-nls --disable-shared --disable-threads --enable-languages=c --with-abi=64

出错信息:

configure: error: Building GCC requires GMP 4.1+ and MPFR 2.3.2+.

Try the --with-gmp and/or --with-mpfr options to specify their locations.

Copies of these libraries' source code can be found at their respective

hosting sites as well as at ftp://gcc.gnu.org/pub/gcc/infrastructure/.

See also http://gcc.gnu.org/install/prerequisites.html for additional info.

If you obtained GMP and/or MPFR from a vendor distribution package, make

sure that you have installed both the libraries and the header files.

They may be located in separate packages.

参考解决办法:

http://ftp.gnu.org/gnu/gmp/   #gmp下载

http://ftp.gnu.org/gnu/mpfr/  #mpfr下载

$ tar xf tar xf gmp-5.0.1.tar.bz2

$ tar xf mpfr-3.0.0.tar.bz2

$ mv gmp-5.0.1/ gmp 

$ mv mpfr-3.0.0/ mpfr 

$ mv gmp/ mpfr/ gcc-4.4.2/

$ cd gcc-build

$ ../gcc-4.4.2/configure --prefix=/opt/loongson-cross-tools/usr --target=mipsel-pc-linux-gnu --with-sysroot=/opt/loongson-cross-tools --disable-multilib --with-newlib --disable-nls --disable-shared --disable-threads --enable-languages=c --with-abi=64

$ make all-gcc

出错信息:

checking whether stripping libraries is possible... yes

checking if libtool supports shared libraries... yes

checking whether to build shared libraries... no

checking whether to build static libraries... yes

checking whether gcc __attribute__ ((mode (XX))) works... yes

checking for recent GMP... yes

checking for gmp internal files... configure: error: header files gmp-impl.h and longlong.h not found

make: *** [configure-mpfr] Error 1

参考解决办法:

mpfr3.0mpfr2.4.2

因为mpfr3.0改了默认路径(网上如此说)

$ tar xf mpfr-2.4.2.tar.bz2

$ mv mpfr-2.4.2/ mpfr 

$ rm gcc-4.4.2/mpfr

$ mv mpfr gcc-4.4.2

$ make all-gcc

$ make all-target-libgcc

$ make install-gcc

$ make install-target-libgcc

参考资料:

https://heiher.info/916.html

http://www.linuxsir.org/bbs/showthread.php?t=338748

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44455

http://blog.sina.com.cn/s/blog_4e9da0010100dhvk.html

阅读(356) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
### 关于龙芯架构的交叉编译工具链 #### 工具链的选择 对于龙芯架构,官方推荐使用的交叉编译工具链能够有效支持其特定指令集和硬件特性[^1]。这有助于开发人员构建针对龙芯处理器优化的应用程序。 #### 配置交叉编译工具链的关键要素 在配置用于龙芯架构的交叉编译工具链时,需特别关注以下几个参数设置: - **ARCH**: 指定目标体系结构,在龙芯的情况下通常为`mipsel`或`loongarch64`。 - **CROSS_COMPILE**: 这一变量定义了前缀名,它告诉编译器使用哪个具体的工具链二进制文件来执行操作。 - **PATH**: 路径环境变量应包含交叉编译工具的位置以便系统可以找到这些工具并正确调用它们[^2]。 #### 具体步骤说明 以下是基于已有资料整理的一个典型流程: 1. **下载合适的GCC版本** 参考相关文档提到的信息,可以选择适合的GCC版本进行安装。例如,gcc-4.4.7是一个被提及较多的稳定版次,并提供了专门面向龙芯平台的支持包(如 `gcc-4.4.7-7215-n64-loongson.tar.gz`)[^3]。 2. **解压与路径设定** 将下载好的压缩包解压到指定目录下,并确保该目录下的bin子目录已被加入系统的全局搜索路径中去。这样做的目的是让后续命令可以直接识别所安装的交叉编译器而无需每次都手动指明全路径。 3. **实际应用中的实例展示——以OpenSSL为例** 如果打算利用上述准备完毕后的工具链来进行某些开源项目的移植工作,则可参照具体案例学习如何实践整个过程。比如下面给出了一段有关于跨平台编译 OpenSSL 的脚本片段[^4]: ```bash #!/bin/bash export ARCH=loongarch64 export CROSS_COMPILE=/path/to/toolchain/bin/loongarch64-linux-gnu- ./Configure linux-generic64 --prefix=$HOME/output_dir no-shared no-dso -fPIC $* make depend && make CC="${CROSS_COMPILE}gcc" make install_sw DESTDIR=$HOME/output_dir/ ``` 此脚本通过导出必要的环境变量以及调整 configure 和 Makefile 中涉及的部分选项实现了自动化处理大部分繁琐细节的目的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值