这段时间,中存储在用软件实现一个3D图形库,因为一些原因,想要使用c++11中的东西。被迫自己编译gcc4.7. 在这个过程中传到了很多的问题,经过不懈的努力终于是成功编译出来了,现在记录一下,算作个备份。
我是在Ubuntu11.10上编译的.会到了如下错误
1.configure错误,说没有gmp,什么的。
2. undefined reference to `lexer_line'
3. fatal error: bits/predefs.h :File or directory not found
4. ld can't find crti.o
相应的解决如下:
1. apt-get install libgmp10-dev libmpfr-dev libmpc-dev
2. apt-get install flex bison
3. 4. 在网上下了一个编译脚本,直接运行就行了
接下来是且这个脚本编译的过程:
1. 按照上面1和2安装好gmp,等等;
2. 到官网上下载代码放在 $HOME/src/gcc-4.7/files/中
3. 下载附件中的脚本,修改PKG_SNAPSHOT_VER和TARGET_SYSTEM_TYPE,然后直接运行即可。
4. 按脚本运行的提示完成最后的工作(比如建立符号链接啊什么的)
脚本如下:
#!/bin/sh
# Filename: build_gcc-snapshot.sh
# Created: 15-Mar-2011
#RunAs: user or root
# Last Changed: 09-Oct-2011
export LANG=C
export LC_ALL=C
PKG_NAME="gcc"
PKG_VER="4.7"
PKG_SNAPSHOT_VER="4.7-20120128"
BASE_DIR="$HOME/src/${PKG_NAME}-${PKG_VER}"
SRC_DIR="${BASE_DIR}/${PKG_NAME}-${PKG_SNAPSHOT_VER}"
BUILD_DIR="${BASE_DIR}/gcc-build"
DL_DIR="${BASE_DIR}/files"
DL_FILE="${PKG_NAME}-${PKG_SNAPSHOT_VER}.tar.bz2"
PATCHES_DIR="${BASE_DIR}/patches"
BUILD_SYSTEM_TYPE=$(dpkg-architecture -qDEB_BUILD_GNU_TYPE)
HOST_SYSTEM_TYPE=$(dpkg-architecture -qDEB_HOST_GNU_TYPE)
TARGET_SYSTEM_TYPE="x86_64-linux-gnu"
HOST_SYSTEM_MULTIARCH_TYPE=$(dpkg-architecture -qDEB_HOST_MULTIARCH)
PREFIX="/opt/${PKG_NAME}-${PKG_VER}"
LIB_DIR="${PREFIX}/lib"
LIB_EXEC_DIR="${PREFIX}/lib"
BUILD_LOG_FILE="${BASE_DIR}/make.log"
GCC_VER_FOR_BUILD="4.6"
CC_FOR_BUILD="gcc-${GCC_VER_FOR_BUILD}"
CXX_FOR_BUILD="g++-${GCC_VER_FOR_BUILD}"
CPP_FOR_BUILD="cpp-${GCC_VER_FOR_BUILD}"
export CC="${CC_FOR_BUILD}" CXX="${CXX_FOR_BUILD}" CPP="${CPP_FOR_BUILD}"
echo "##### CC ... $CC"
echo "##### CXX ... $CXX"
echo "##### CPP ... $CPP"
MULTIARCH_FLAGS="-B/usr/lib/${HOST_SYSTEM_MULTIARCH_TYPE} -I/usr/include/${HOST_SYSTEM_MULTIARCH_TYPE}"
export CFLAGS="-g -O2"
export CXXFLAGS="${CFLAGS}"
export CFLAGS_FOR_TARGET="${CFLAGS} ${MULTIARCH_FLAGS}"
export CXXFLAGS_FOR_TARGET="${CXXFLAGS} ${MULTIARCH_FLAGS}"
##LD_PRELOAD_FOR_BUILD="${PREFIX}/lib/libgcc_s.so.1"
##export LD_PRELOAD=${LD_PRELOAD_FOR_BUILD}
MAKE_JOBS="3"
echo "##### MAKE_JOBS ... ${MAKE_JOBS}"
test -e ${BASE_DIR} || mkdir -p ${BASE_DIR}
echo "##### Base directory ... ${BASE_DIR}"
echo "##### Unpacking ${DL_FILE} ..."
tar -xf ${DL_DIR}/${DL_FILE} -C ${BASE_DIR}
echo "##### Finished unpacking."
test -e ${BUILD_DIR} || mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
echo "##### Build directory ... $PWD"
# HELP: http://www.linuxfromscratch.org/lfs/view/development/chapter06/gcc.html
# NOTE: apt-get install libgmp10-dev libmpfr-dev libmpc-dev
echo "##### Configuring gcc-build ..."
../${PKG_NAME}-${PKG_SNAPSHOT_VER}/configure
--prefix=${PREFIX}
--libdir=${LIB_DIR}
--libexecdir=${LIB_EXEC_DIR}
--program-suffix=-${PKG_VER}
--enable-clocale=gnu
--enable-languages=c,c++
--enable-shared
--enable-threads=posix
--disable-bootstrap
--disable-libssp
--disable-multilib
--disable-nls
--with-system-zlib
--without-cloog
--without-ppl
--with-arch-32=i586 --with-tune=generic
--build=${BUILD_SYSTEM_TYPE} --host=${HOST_SYSTEM_TYPE} --target=${TARGET_SYSTEM_TYPE}
echo "##### Finished configuring."
echo "##### Compiling gcc-build ..."
make FLAGS_FOR_TARGET="${FLAGS_FOR_TARGET} ${MULTIARCH_FLAGS}" -j${MAKE_JOBS} 2>&1 | tee ${BUILD_LOG_FILE}
echo "##### Finished compiling."
echo "NOTE #1: Before installing your shiny new gcc run the gcc-testsuite to check your build is OK!"
echo "NOTE #2: Don't forget to generate symlinks in system's bin directory!"
echo "EXAMPLE: sudo ln -sf ${PREFIX}/bin/${PKG_NAME}-${PKG_VER} /usr/bin/${PKG_NAME}-${PKG_VER}"
echo "NOTE #3: Don't forget to add ${PREFIX}/lib' to /etc/ld.so.conf.d/${TARGET_SYSTEM_TYPE}.conf!"
echo "EXAMPLE: sudo ldconfig -v"
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。