最简单方法
使用buildroot工具进行编译
参考
http://blog.sina.com.cn/s/blog_6314c0900101ent6.html
build-root下载地址
http://buildroot.uclibc.org/downloads/
下载buildroot后,解压,进入目录输入make menuconfig
在target选项选择要交叉编译的环境
Toolchain中选择编译的gcc版本、是否编译g++以及glibc版本(详见参考)
设置ok后,退出 选yes保存
sudo apt-get install build-essential bison flex
make -j8
可能报错:
1.缺少安装东西(You need *************)
解决:
按照提示进行apt-get安装(自行百度)
2.You need at least one UTF8 locale to build a toolchain supporting locales
问题:没有设置语言
解决:
apt-get install locales
3.#define 关于宏的报错
问题:是因为编译加了-Werror
解决:哪个项目报错,去目录下文件夹找Makefile 用/Werror找到 删除代码就
行
喝杯coffee,静等
源码编译版(以mips为例)
1.源码
gcc各版本浏览地址:http://ftp.gnu.org/gnu/gcc
2.安装gcc必须三个库///configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
参考:
https://blog.csdn.net/wuyupei1213434654/article/details/8847932?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
https://blog.csdn.net/iteye_21170/article/details/82543719
https://blog.csdn.net/qq_23438131/article/details/52385843
3.编译 binutils(binutils装2.27版本)
下载 ,解压 ./configure make
报错:
先安装texinfo。
http://ftp.gnu.org/gnu/texinfo/(5.0以上版本)
再
../binutils-2.20.1/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 --disable-werror
报错
bfd.texinfo:325: unknown command `colophon'
../../../binutils-2.23.2/bfd/doc/bfd.texinfo:336: unknown command `cygnus'
执行
sed -i -e 's/@colophon/@@colophon/' \ -e 's/doc@cygnus.com/doc@@cygnus.com/' ../binutils-2.23.2/bfd/doc/bfd.texinfo
参考:
https://www.cnblogs.com/sukai/p/3657215.html
https://stackoverflow.com/questions/19885825/binutils-cross-compile-error
4.编译gcc
../gcc-4.9.3/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,c++ --with-abi=64 --libdir=/usr/lib -with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/ --with-mpc=/usr/local/mpc-0.8.1/
make all-gcc
报错:checking whether byte ordering is bigendian... no
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in /opt/gcc-build/gcc': configure: WARNING: C++ preprocessor "/lib/cpp" fails sanity check See 'config.log' for more details.
checking for unordered_map... no
checking for tr1/unordered_map... no
checking for ext/hash_map... no
checking dependency style of g++... none
configure: error: no usable dependency style found
安装依赖库
sudo apt-get install build-essential
ok,编译完成,有的报错没遇到可以自行百度