Problems and Solutions for compiling GCC on Ubuntu

Source: Internet
Author: User
Tags gmp lexer
During this time, I was using software to implement a 3D graphics library. For some reason, I wanted to use something in c ++ 11. I was forced to compile gcc4.7by myself. A lot of problems were encountered in this process. After unremitting efforts, I finally compiled it successfully. Now I want to record it as a backup. I compiled it on Ubuntu11.10. the following error will be returned: 1. configure error, saying there is no gmp or something. 2. undefinedreferenceto 'lexer _ line' 3

During this time, I was using software to implement a 3D graphics library. For some reason, I wanted to use something in c ++ 11. I was forced to compile gcc4.7by myself. A lot of problems were encountered in this process. After unremitting efforts, I finally compiled it successfully. Now I want to record it as a backup.

I compiled it on Ubuntu11.10. the following error occurs:

1. configure error, saying there is no gmp or something.

2. undefined reference to 'lexer _ Line'

3. fatal error: bits/predefs. h: File or directory not found

4. ld can't find crti. o

The solution is as follows:

1. apt-get install libgmp10-dev libmp fr-dev libmp C-dev

2. apt-get install flex bison

3. 4. Compile the script on the Internet and run it directly.

The following is the script compilation process:

1. Install gmp according to steps 1 and 2 above, and so on;

2. Download the code on the official website in $ HOME/src/gcc-4.7/files/

3. Download the script in the attachment, modify PKG_SNAPSHOT_VER and TARGET_SYSTEM_TYPE, and then run it directly.

4. Follow the script running prompts to complete the final work (such as creating a symbolic link or something)

The script is as follows:

  1. #! /Bin/sh
  2. # Filename: build_gcc-snapshot.sh
  3. # Created: 15 to Mar-2011
  4. # RunAs: user or root
  5. # Last Changed: 09-Oct-2011
  6. ExportLANG=C
  7. ExportLC_ALL=C
  8. PKG_NAME="Gcc"
  9. PKG_VER="4.7"
  10. PKG_SNAPSHOT_VER=4.7-20120128"
  11. BASE_DIR="$ HOME/src/$ {PKG_NAME}-$ {PKG_VER }"
  12. SRC_DIR="$ {BASE_DIR}/$ {PKG_NAME}-$ {PKG_SNAPSHOT_VER }"
  13. BUILD_DIR="$ {BASE_DIR}/gcc-build"
  14. DL_DIR="$ {BASE_DIR}/files"
  15. DL_FILE="Zookeeper pkg_name1_-zookeeper pkg_snapshot_ver=.tar.bz2"
  16. PATCHES_DIR="$ {BASE_DIR}/patches"
  17. BUILD_SYSTEM_TYPE= $ (Dpkg-architecture-qDEB_BUILD_GNU_TYPE)
  18. HOST_SYSTEM_TYPE= $ (Dpkg-architecture-qDEB_HOST_GNU_TYPE)
  19. TARGET_SYSTEM_TYPE=X86_64-linux-gnu"
  20. HOST_SYSTEM_MULTIARCH_TYPE= $ (Dpkg-architecture-qDEB_HOST_MULTIARCH)
  21. PREFIX="/Opt/$ {PKG_NAME}-$ {PKG_VER }"
  22. LIB_DIR="$ {PREFIX}/lib"
  23. LIB_EXEC_DIR="$ {PREFIX}/lib"
  24. BUILD_LOG_FILE="$ {BASE_DIR}/make. log"
  25. GCC_VER_FOR_BUILD="4.6"
  26. CC_FOR_BUILD="Gcc-$ {GCC_VER_FOR_BUILD }"
  27. CXX_FOR_BUILD="G ++-$ {GCC_VER_FOR_BUILD }"
  28. CPP_FOR_BUILD="Cpp-$ {GCC_VER_FOR_BUILD }"
  29. ExportCC="$ {CC_FOR_BUILD }" CXX="$ {CXX_FOR_BUILD }" CPP="$ {CPP_FOR_BUILD }"
  30. Echo "##### CC... $ CC"
  31. Echo "##### CXX... $ CXX"
  32. Echo "##### CPP... $ CPP"
  33. MULTIARCH_FLAGS="-B/usr/lib/$ {HOST_SYSTEM_MULTIARCH_TYPE}-I/usr/include/$ {HOST_SYSTEM_MULTIARCH_TYPE }"
  34. ExportCFLAGS="-G-O2"
  35. ExportCXXFLAGS="$ {CFLAGS }"
  36. ExportCFLAGS_FOR_TARGET="$ {CFLAGS }$ {MULTIARCH_FLAGS }"
  37. ExportCXXFLAGS_FOR_TARGET="$ {CXXFLAGS }$ {MULTIARCH_FLAGS }"
  38. ##LD_PRELOAD_FOR_BUILD="$ {PREFIX}/lib/libgcc_s.so.1"
  39. # ExportLD_PRELOAD=$ {LD_PRELOAD_FOR_BUILD}
  40. MAKE_JOBS="3"
  41. Echo "##### MAKE_JOBS... $ {MAKE_JOBS }"
  42. Test-e $ {BASE_DIR} | mkdir-p $ {BASE_DIR}
  43. Echo "##### Base directory... $ {BASE_DIR }"
  44. Echo "##### Unpacking $ {DL_FILE }..."
  45. Tar-xf $ {DL_DIR}/$ {DL_FILE}-C $ {BASE_DIR}
  46. Echo "##### Finished unpacking ."
  47. Test-e $ {BUILD_DIR} | mkdir-p $ {BUILD_DIR}
  48. Cd $ {BUILD_DIR}
  49. Echo "##### Build directory... $ PWD"
  50. # HELP: http://www.linuxfromscratch.org/lfs/view/development/chapter06/gcc.html
  51. # NOTE: apt-get install libgmp10-dev libmp fr-dev libmp C-dev
  52. Echo "##### using ing gcc-build ..."
  53. ../$ {PKG_NAME}-$ {PKG_SNAPSHOT_VER}/configure \
  54. -- Prefix=$ {PREFIX }\
  55. -- Libdir=$ {LIB_DIR }\
  56. -- Libexecdir=$ {LIB_EXEC_DIR }\
  57. -- Program-suffix=-$ {PKG_VER }\
  58. -- Enable-clocale=Gnu\
  59. -- Enable-ages=C, C ++ \
  60. -- Enable-shared \
  61. -- Enable-threads=Posix\
  62. -- Disable-bootstrap \
  63. -- Disable-libssp \
  64. -- Disable-multilib \
  65. -- Disable-nls \
  66. -- With-system-zlib \
  67. -- Without-cloog \
  68. -- Without-ppl \
  69. -- With-arch-32=I586 -- With-tune=Generic\
  70. -- Build=$ {BUILD_SYSTEM_TYPE}-- Host=$ {HOST_SYSTEM_TYPE}-- Target=$ {TARGET_SYSTEM_TYPE}
  71. Echo "##### Finished sorting ."
  72. Echo "##### Compiling gcc-build ..."
  73. MakeFLAGS_FOR_TARGET="$ {FLAGS_FOR_TARGET }$ {MULTIARCH_FLAGS }"-J $ {MAKE_JOBS} 2>& 1 | tee $ {BUILD_LOG_FILE}
  74. Echo "##### Finished compiling ."
  75. Echo "NOTE #1: Before installing your shiny new gcc run the gcc-testsuite to check your build is OK! "
  76. Echo "NOTE #2: Don't forget to generate symlinks in system's bin directory! "
  77. Echo "EXAMPLE: sudo ln-sf $ {PREFIX}/bin/$ {PKG_NAME}-$ {PKG_VER}/usr/bin/$ {PKG_NAME}-$ {PKG_VER }"
  78. Echo "NOTE #3: Don't forget to add $ {PREFIX}/lib 'to/etc/ld. so. conf. d/$ {TARGET_SYSTEM_TYPE}. conf! "
  79. Echo "EXAMPLE: sudo ldconfig-v"
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.