buildroot编译misp-linux-g++工具
基于qca953x 路由平台,buildroot版本为buildroot-2009.08;
1.把toolchain 先distclean下
cd build/buildroot-2009.08/
make distclean
2.勾选Build/install c++ compiler and libstdc++
make menconfig
在Toolchain里面选上你需要的编译工具,比如g++是
[ ] Build/install c++ compiler and libstdc++?
移动到上面,按一下空格,就会变成
[*] Build/install c++ compiler and libstdc++?
3.make
如果遇到以下错误
In file included from /trunk/build/buildroot-2009.08/toolchain_build_mips/gcc-4.3.3/libstdc++-v3/include/precompiled/extc++.h:52:
/trunk/build/buildroot-2009.08/toolchain_build_mips/gcc-4.3.3-final/mips-linux-uclibc/libstdc++-v3/include/ext/rope:1109:13: error: macro "index" requires
2 arguments, but only 1 given
解决办法:
make clean
然后
修改
trunk\build\buildroot-2009.08\toolchain_build_mips\gcc-4.3.3\libstdc++-v3\include\ext下的两个文件rope和ropeimpl.h
rope
#include <bits/gthr.h>
#include <tr1/functional>
#undef index ---增加这一句
# ifdef __GC
# define __GC_CONST const
ropeimpl.h
#include <ext/memory> // For uninitialized_copy_n
#include <ext/numeric> // For power
#undef index
---增加这一句
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
也可以做个gcc patch文件999-gcc-4.3.3-libstdcppv3-include-ext-rope.patch放到trunk\build\buildroot-2009.08\toolchain\gcc\4.3.3目录下
打patch方法:
diff -urN gcc-4.3.3.orig/libstdc++-v3/include/ext/ropeimpl.h gcc-4.3.3/libstdc++-v3/include/ext/ropeimpl.h > 999-gcc-4.3.3-libstdcppv3-include-ext-ropeimpl.patch
diff -urN gcc-4.3.3.orig/libstdc++-v3/include/ext/rope gcc-4.3.3/libstdc++-v3/include/ext/rope > 999-gcc-4.3.3-libstdcppv3-include-ext-rope.patch
附 999-gcc-4.3.3-libstdcppv3-include-ext-rope.patch文件内容
diff -urN gcc-4.3.3.orig/libstdc++-v3/include/ext/rope gcc-4.3.3/libstdc++-v3/include/ext/rope
--- gcc-4.3.3.orig/libstdc++-v3/include/ext/rope 2016-06-12 10:59:14.953284600 +0800
+++ gcc-4.3.3/libstdc++-v3/include/ext/rope 2016-06-14 14:46:07.568100900 +0800
@@ -59,6 +59,8 @@
#include <bits/gthr.h>
#include <tr1/functional>
+#undef index
+
# ifdef __GC
# define __GC_CONST const
# else
diff -urN gcc-4.3.3.orig/libstdc++-v3/include/ext/ropeimpl.h gcc-4.3.3/libstdc++-v3/include/ext/ropeimpl.h
--- gcc-4.3.3.orig/libstdc++-v3/include/ext/ropeimpl.h2016-06-12 10:59:14.953284600 +0800
+++ gcc-4.3.3/libstdc++-v3/include/ext/ropeimpl.h 2016-06-14 14:46:42.177097000 +0800
@@ -54,6 +54,8 @@
#include <ext/memory> // For uninitialized_copy_n
#include <ext/numeric> // For power
+#undef index
+
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
using std::size_t;
另外建议同时改一个配置文件
trunk/build/buildroot-2009.08/toolchain/uClibc/board953x.config
将
UCLIBC_SUSV3_LEGACY改为
UCLIBC_SUSV3_LEGACY=y
4.export工具链
编译完后的工具链位于trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/bin下面;
ls
trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/bin
ccache mips-linux-cc mips-linux-gcov mips-linux-objcopy mips-linux-strip mips-linux-uclibc-cpp mips-linux-uclibc-gprof mips-linux-uclibc-ranlib
ldconfig mips-linux-c++filt mips-linux-gdb mips-linux-objdump mips-linux-uclibc-addr2line mips-linux-uclibc-g++ mips-linux-uclibc-ld mips-linux-uclibc-readelf
ldd mips-linux-cpp mips-linux-gprof mips-linux-ranlib mips-linux-uclibc-ar mips-linux-uclibc-gcc mips-linux-uclibc-ldconfig mips-linux-uclibc-size
mips-linux-addr2line mips-linux-g++ mips-linux-ld mips-linux-readelf mips-linux-uclibc-as mips-linux-uclibc-gcc-4.3.3 mips-linux-uclibc-ldd mips-linux-uclibc-sstrip
mips-linux-ar mips-linux-gcc mips-linux-ldconfig mips-linux-size mips-linux-uclibc-c++ mips-linux-uclibc-gccbug mips-linux-uclibc-nm mips-linux-uclibc-strings
mips-linux-as mips-linux-gcc-4.3.3 mips-linux-ldd mips-linux-sstrip mips-linux-uclibc-cc mips-linux-uclibc-gcov mips-linux-uclibc-objcopy mips-linux-uclibc-strip
mips-linux-c++ mips-linux-gccbug mips-linux-nm mips-linux-strings mips-linux-uclibc-c++filt mips-linux-uclibc-gdb mips-linux-uclibc-objdump
cp -r
trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/bin ~/build_mips/
设置环境变量以让 Shell 能够访问到工具链。运行命令
export PATH=$PATH:~/build_mips/bin
此设置只在当前的 Shell 里有效。
或者
加入环境变量
# vim /etc/profile
加入下面这一行:
export PATH=$PATH:~/build_mips/bin
# source /etc/profile //在重启之前,每次打开一个终端都要再运行一次这个
编译好的libc++库目录位于
trunk\build\buildroot-2009.08\build_mips\staging_dir\usr\lib
trunk\build\buildroot-2009.08\build_mips\staging_dir\usr\mips-linux-uclibc\lib
$ ls trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/lib
crt1.o gcc libc_pic.a libcrypt.so libdl_pic.a libm.a libnsl.a libpthread.a libresolv.a librt.a libutil.a Scrt1.o
crti.o ldscripts libcrypt.a libc.so libdl.so libm_pic.a libnsl_pic.a libpthread_pic.a libresolv_pic.a librt_pic.a libutil_pic.a uclibc_nonshared.a
crtn.o libc.a libcrypt_pic.a libdl.a libiberty.a libm.so libnsl.so libpthread.so libresolv.so librt.so libutil.so
$ ls trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/mips-linux-uclibc/lib
libgcc_s.so libgomp.a libgomp.so libgomp.so.1.0.0 libiberty.a libmudflap.la libmudflap.so.0 libmudflapth.a libmudflapth.so libmudflapth.so.0.0.0 libstdc++.la libstdc++.so.6 libsupc++.a
libgcc_s.so.1 libgomp.la libgomp.so.1 libgomp.spec libmudflap.a libmudflap.so libmudflap.so.0.0.0 libmudflapth.la libmudflapth.so.0 libstdc++.a libstdc++.so libstdc++.so.6.0.10 libsupc++.la
5.执行下面命令,如果有类似结果显示,说明工具链编译ok
$ mips-linux-gcc --version
mips-linux-gcc (GCC) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ mips-linux-g++ --version
mips-linux-g++ (GCC) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
6.
mips-linux-g++ 的socket.h expected initializer before 'throw' error:
trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/include/bits/socket.h:271: error: expected initializer before 'throw'
修改trunk/build/buildroot-2009.08/build_mips/staging_dir/usr/include/bits/socket.h文件:line 271
+ CMSG_ALIGN (sizeof (struct cmsghdr)))
#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
/*--------------------主要是修改下面这个函数--------------------------*/
-extern struct cmsghdr * __NTH (__cmsg_nxthdr (struct msghdr *__mhdr,
- struct cmsghdr *__cmsg)) __THROW;
+extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
+ struct cmsghdr *__cmsg) __THROW;
/*-----------------------------------------------*/
#ifdef __USE_EXTERN_INLINES
# ifndef _EXTERN_INLINE
或者打个patch
build/buildroot-2009.08/toolchain_build_mips/uClibc-0.9.30/include/bits$ ls socket.h -l
socket.h -> ../../libc/sysdeps/linux/mips/bits/socket.h
build/buildroot-2009.08/toolchain_build_mips/uClibc-0.9.30/libc/sysdeps/linux/mips/bits/socket.h
diff -urN uClibc-0.9.30/libc/sysdeps/linux/mips/bits/socket.h.orig uClibc-0.9.30/libc/sysdeps/linux/mips/bits/socket.h > uClibc-0.9.30-015-include-socket.h.patch
diff -urN uClibc-0.9.30/include/bits/socket.h.orig uClibc-0.9.30/include/bits/socket.h > uClibc-0.9.30-015-include-socket.h.patch
uClibc-0.9.30-015-include-socket.h.patch内容
--- uClibc-0.9.30/libc/sysdeps/linux/mips/bits/socket.h.orig2016-06-12 11:04:17.491075200 +0800
+++ uClibc-0.9.30/libc/sysdeps/linux/mips/bits/socket.h 2016-06-14 15:27:14.234586900 +0800
@@ -268,8 +268,8 @@
+ CMSG_ALIGN (sizeof (struct cmsghdr)))
#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
-extern struct cmsghdr * __NTH (__cmsg_nxthdr (struct msghdr *__mhdr,
- struct cmsghdr *__cmsg)) __THROW;
+extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
+ struct cmsghdr *__cmsg) __THROW;
#ifdef __USE_EXTERN_INLINES
# ifndef _EXTERN_INLINE
# define _EXTERN_INLINE extern __inline