简体   繁体   English

如何使用GMP,MPFR,MPC,ELF逐个安装GCC,无需共享库?

[英]How to install GCC piece by piece with GMP, MPFR, MPC, ELF, without shared libraries?

How do I install GCC (the GNU Compiler Collection) piece by piece, using the current version, 如何使用当前版本逐个安装GCC(GNU编译器集合),
using the correct versions of dependencies, not using a package manager (like yum, rpm, apt, dpkg), and not using shared libraries? 使用正确版本的依赖项,而不是使用包管理器(如yum,rpm,apt,dpkg),而不使用共享库?

Typical developers will likely want to install GCC the typical way, use your package manager (yum, rpm, apt, dpkg, port, brew, etc.) or follow the instructions here ( http://gcc.gnu.org/wiki/InstallingGCC ). 典型的开发人员可能希望以典型的方式安装GCC,使用您的包管理器(yum,rpm,apt,dpkg,port,brew等)或按照此处的说明进行操作( http://gcc.gnu.org/wiki/ InstallingGCC )。

My question is how to install GCC piece by piece, without shared libraries. 我的问题是如何一块一块地安装GCC,没有共享库。

  • I want a fully-independent GCC that can be moved around my system without using any shared libraries, and without creating any shared libraries. 我想要一个完全独立的GCC,可以在不使用任何共享库的情况下在我的系统中移动,而无需创建任何共享库。
  • This is what GCC calls "the difficult way" and it is not recommended for typical users. 这就是GCC所说的“困难之路”,不建议普通用户使用。

GCC depends on: GCC取决于:

  • GMP: GNU Multiple Precision Arithmetic Library GMP:GNU多精度算术库
  • MPFR: GNU Multiple-precision floating-point rounding library MPFR:GNU多精度浮点舍入库
  • MPC: GNU Multiple-precision C library MPC:GNU多精度C库
  • ELF: Executable and Linkable Format library ELF:可执行和可链接格式库
  • PPL: Parma Polyhedra Library (optional, for memory optimizations) PPL:Parma Polyhedra库(可选,用于内存优化)

The Easy Way 简单的方法

If you're a typical developer, you can install the easy way, using instructions at http://gcc.gnu.org/wiki/InstallingGCC or your system package manager such as: 如果您是典型的开发人员,可以使用http://gcc.gnu.org/wiki/InstallingGCC上的说明或系统软件包管理器安装简单方法,例如:

apt  install gcc  # for Debian, Ubuntu, etc.
yum  install gcc  # for RedHat, CentOS, etc.
brew install gcc  # for Mac OS X

The Hard Way 困难的方式

GCC says the answer here is "the hard way" because it builds everything piece by piece, and does not use shared libraries. GCC说这里的答案是“艰难的”,因为它逐个构建所有东西,并且不使用共享库。

GCC infrastructure GCC基础设施

Get the GCC infrastructure: 获得GCC基础设施:

ftp://gcc.gnu.org/pub/gcc/infrastructure/

Put downloads in a temp directory (you can use whatever directory you want). 将下载放在临时目录中(您可以使用您想要的任何目录)。

/opt/downloads

Build the infrastructure in a temp directory that is different than the downloads directory or its subdirectories: 在与下载目录或其子目录不同的临时目录中构建基础结构:

/tmp/gcc

Configure the infrastructure using static libraries like this: 使用如下静态库配置基础结构:

./configure --disable-shared --enable-static --prefix=/tmp/gcc

The --disable-shared flag may be worth a closer look depending on your needs. --disable-shared标志可能值得仔细查看,具体取决于您的需求。 I use --disable-shared because I am building static code only, and I want to make sure that I don't build any shared code. 我使用--disable-shared因为我只构建静态代码,并且我想确保我不构建任何共享代码。 My need is to move the resulting GCC around my drives easily, so I want all static code, and I do not want any shared code. 我需要的是轻松地将生成的GCC移动到我的驱动器周围,所以我想要所有静态代码,而且我不需要任何共享代码。 If you prefer shared code, omit the --disable-shared flag. 如果您更喜欢共享代码,请省略--disable-shared标志。

Versions 版本

When you run any of the commands in this answer, be sure to update the commands to use the current GCC version number that matches your needs. 当您运行此答案中的任何命令时,请务必更新命令以使用符合您需要的当前GCC版本号。 The commands in this answer are for GCC 4.6.2. 本答案中的命令适用于GCC 4.6.2。

Note that the GCC documentation says: "While any sufficiently new version of required tools usually work, library requirements are generally stricter. Newer versions may work in some cases, but it's safer to use the exact versions documented." 请注意,GCC文档说:“虽然任何足够新版本的所需工具通常都有效,但库要求通常更为严格。新版本可能在某些情况下有效,但使用所记录的确切版本更安全。”

GMP GMP

GMP is the GNU Multiple Precision Arithmetic Library. GMP是GNU多精度算术库。

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
bunzip2 gmp-4.3.2.tar.bz2
tar xvf gmp-4.3.2.tar
cd gmp-4.3.2
./configure --disable-shared --enable-static --prefix=/tmp/gcc
make && make check && make install

MPFR MPFR

MPFR is the GNU Multiple-precision floating-point rounding library. MPFR是GNU多精度浮点舍入库。 It depends on GMP. 这取决于GMP。

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
bunzip2 mpfr-2.4.2.tar.bz2
tar xvf mpfr-2.4.2.tar
cd mpfr-2.4.2
./configure --disable-shared --enable-static --prefix=/tmp/gcc --with-gmp=/tmp/gcc
make && make check && make install

MPC MPC

MPC is the GNU Multiple-precision C library. MPC是GNU多精度C库。 It depends on GMP and MPFR. 这取决于GMP和MPFR。

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
tar zxvf mpc-0.8.1.tar.gz
cd mpc-0.8.1
./configure --disable-shared --enable-static --prefix=/tmp/gcc --with-gmp=/tmp/gcc --with-mpfr=/tmp/gcc
make && make check && make install

ELF ELF

ELF stands for Executable and Linkable Format. ELF代表可执行和可链接格式。 This library provides architecture-independent size and endian support. 该库提供与体系结构无关的大小和endian支持。

wget http://www.mr511.de/software/libelf-0.8.13.tar.gz
tar zxvf libelf-0.8.13.tar.gz
cd libelf-0.8.13
./configure --disable-shared --enable-static --prefix=/tmp/gcc
make && make check && make install

GCC GCC

GCC is the GNU Compiler Collection. GCC是GNU编译器集合。 It depends on GMP, MPFR, MPC, and ELF. 它取决于GMP,MPFR,MPC和ELF。

wget http://www.netgull.com/gcc/releases/gcc-4.6.2/gcc-4.6.2.tar.gz
tar zxvf gcc-4.6.2.tar.gz

Build gcc in a scratch directory on the same mount point. 在同一个挂载点的scratch目录中构建gcc。 (Building it within /tmp would trigger cross compile host issues) (在/ tmp中构建它会触发交叉编译主机问题)

mkdir -p /opt/downloads/gcc-4.6.2-scratch
cd /opt/downloads/gcc-4.6.2-scratch

The configure command and its flags must be all on one command line (this post shows them on separate lines just because of web page width). configure命令及其标志必须全部在一个命令行上(由于网页宽度,此帖子在单独的行中显示它们)。

Note: We use the full path to configure and do not set library path environment variables. 注意:我们使用完整路径进行配置,不要设置库路径环境变量。 We choose to disable bootstrap and disable shared libraries because we don't want them (typical users may want both), and to use posix threads and to flags that are defaults because we want them (typical users may want to use other threads or skip default flags). 我们选择禁用引导程序并禁用共享库,因为我们不希望它们(典型用户可能想要两者),并使用posix线程和默认标志,因为我们需要它们(典型用户可能想要使用其他线程或跳过默认标志)。 YMMV and read about the flags here YMMV并在这里阅读标志

/opt/downloads/gcc-4.6.2/configure
  --disable-shared
  --disable-bootstrap
  --disable-libstdcxx-pch
  --enable-languages=all
  --enable-libgomp
  --enable-lto
  --enable-threads=posix
  --enable-tls
  --with-gmp=/tmp/gcc
  --with-mpfr=/tmp/gcc
  --with-mpc=/tmp/gcc
  --with-libelf=/tmp/gcc
  --with-fpmath=sse
make && make install

This page is great for GCC installation info, how to build it, various flags, and more: 此页面非常适合GCC安装信息,如何构建它,各种标志等:

http://www.acsu.buffalo.edu/~charngda/cc_build.html http://www.acsu.buffalo.edu/~charngda/cc_build.html

Updates 更新

The ppl libraries can be used for memory optimizations: see bugseng.com/products/ppl/Download (Thanks Paul in comments) ppl库可用于内存优化:请参阅bugseng.com/products/ppl/Download(在评论中感谢Paul)

You could run ./contrib/download_prerequisites from the gcc source directory. 您可以从gcc源目录运行./contrib/download_prerequisites。 (Thanks to N7P on reddit) (感谢NdP on reddit)

The accepted answer makes it far more complicated than necessary and is not correct for all versions. 接受答案使它远远超过必要的复杂,并不适用于所有版本的正确。 Building GCC with --disable-shared is usually a very bad idea. 使用--disable-shared构建GCC通常是一个非常糟糕的主意。 See http://gcc.gnu.org/wiki/InstallingGCC for an easier approach. 请参阅http://gcc.gnu.org/wiki/InstallingGCC以获得更简单的方法。

The entire process should be no more difficult than this (replacing 4.6.2 with the version you want to build): 整个过程应该不比这更难(用你想要构建的版本替换4.6.2):

tar xzf gcc-4.6.2.tar.gz
cd gcc-4.6.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.6.2/configure --prefix=$HOME/GCC-4.6.2 
make
make install

(But please read the link above anyway, it contains useful information.) (但请阅读上面的链接,它包含有用的信息。)

Apparently some people on Ubuntu have tons of crap set in their environment which interferes with the GCC build process, and they need to remove that first: 显然,Ubuntu上的一些人在他们的环境中设置了大量垃圾,干扰了GCC的构建过程,他们需要首先删除它:

unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE LD_LIBRARY_PATH

I work on a cluster. 我在一个集群上工作。 Only the master node is connected to the Internet. 只有主节点连接到Internet。 The software on nodes is outdated and generally not maintained. 节点上的软件已过时,通常无法维护。 I don't have root access. 我没有root访问权限。 I have two options: 我有两个选择:

  • build static software I need (computational packages); 构建我需要的静态软件(计算包); or 要么
  • build static compilers. 构建静态编译器。

I chose the second and built gcc, g++ and gfortran. 我选择了第二个并构建了gcc,g ++和gfortran。

I built everything in 我把一切都建成了

PREFIX=$HOME/cmp/soft/sft

and for make I used make我用

THREADS=8

Below, gcc is built with 下面,gcc是用

  • GMP GMP
  • MPFR MPFR
  • MPC MPC
  • ISL ISL
  • CLOOG CLOOG

One can get the latest gcc from here: ftp://gcc.gnu.org/pub/gcc/releases 可以从这里获得最新的gcc: ftp//gcc.gnu.org/pub/gcc/releases

Dependencies are found here: ftp://gcc.gnu.org/pub/gcc/infrastructure 依赖关系可以在这里找到: ftp//gcc.gnu.org/pub/gcc/infrastructure

Dependencies 依赖

I get dependencies with the following script: 我使用以下脚本获得依赖:

#!/bin/sh

# ===========
## variables:

GMP=gmp-4.3.2.tar.bz2
MPFR=mpfr-2.4.2.tar.bz2
MPC=mpc-0.8.1.tar.gz
ISL=isl-0.12.2.tar.bz2
CLOOG=cloog-0.18.1.tar.gz

MIRROR=ftp://gcc.gnu.org/pub/gcc/infrastructure


# ===========
## functions:

extract() {
    if [ -f $1 ]; then
        case $1 in
            *.tar.bz2)   tar xvjf $1    ;;
            *.tar.gz)    tar xvzf $1    ;;
            *.bz2)       bunzip2 $1     ;;
            *.rar)       unrar x $1     ;;
            *.gz)        gunzip $1      ;;
            *.tar)       tar xvf $1     ;;
            *.tbz2)      tar xvjf $1    ;;
            *.tgz)       tar xvzf $1    ;;
            *.zip)       unzip $1       ;;
            *.Z)         uncompress $1  ;;
            *.7z)        7z x $1        ;;
            *)           echo "I don't know how to extract '$1'..." ;;
        esac
    else
        echo "'$1' is not a valid file!"
    fi
}

# ======================
## download and extract:

wget $MIRROR/$GMP
extract $GMP

wget $MIRROR/$MPFR
extract $MPFR

wget $MIRROR/$MPC
extract $MPC

wget $MIRROR/$ISL
extract $ISL

wget $MIRROR/$CLOOG
extract $CLOOG

The following bash function is used below: 以下使用以下bash函数:

mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

Each of the commands below is to be issued in the dir of the lib just downloaded. 以下每个命令都将在刚刚下载的lib的目录中发布。

GMP GMP

mkdircd build
../configure --disable-shared --enable-static --prefix=$PREFIX/gmp
make -j $THREADS && make check && make install

MPFR MPFR

mkdircd build
../configure --with-gmp=$PREFIX/gmp --disable-shared --enable-static --prefix=$PREFIX/mpfr
make -j $THREADS && make install

MPC MPC

mkdircd build
../configure --with-gmp=$PREFIX/gmp --with-mpfr=$PREFIX/mpfr --disable-shared --enable-static --prefix=$PREFIX/mpc
make -j $THREADS && make install

ISL ISL

mkdircd build
../configure --with-gmp-prefix=$PREFIX/gmp --disable-shared --enable-static --prefix=$PREFIX/isl
make -j $THREADS && make install

CLOOG CLOOG

mkdircd build
../configure --with-gmp-prefix=$PREFIX/gmp --with-isl-prefix=$PREFIX/isl --disable-shared --enable-static --prefix=$PREFIX/cloog
make -j $THREADS && make install

gcc GCC

mkdircd build
export LD_LIBRARY_PATH=$PREFIX/gmp/lib:$PREFIX/mpfr/lib:$PREFIX/mpc/lib:$PREFIX/isl/lib:$PREFIX/cloog/lib
export C_INCLUDE_PATH=$PREFIX/gmp/include:$PREFIX/mpfr/include:$PREFIX/mpc/include:$PREFIX/isl/include:$PREFIX/cloog/include
export CPLUS_INCLUDE_PATH=$PREFIX/gmp/include:$PREFIX/mpfr/include:$PREFIX/mpc/include:$PREFIX/isl/include:$PREFIX/cloog/include
../configure --with-gmp=$PREFIX/gmp --with-mpfr=$PREFIX/mpfr --with-mpc=$PREFIX/mpc --with-isl=$PREFIX/isl --with-cloog=$PREFIX/cloog --disable-shared --enable-static --disable-multilib --prefix=$PREFIX/gcc --enable-languages=c,c++,fortran
make -j $THREADS bootstrap && make install

Used what Jonathan above has mentioned except that I had to download gmp and mpfr manually and create soft link (gcc 4.4.2 distribution probably does not have "download_prerequisites") 使用Jonathan上面提到的,除了我必须手动下载gmp和mpfr并创建软链接(gcc 4.4.2发布可能没有“download_prerequisites”)

cd src/gcc-4.4.2
ln -s ~/linux64/gmp-4.2.1  gmp
ln -s ~/linux64/mpfr-2.3.0 mpfr

Btw, using "-with-gmp" and "with-mpfr" with "./configure" gave me "configure: error: cannot compute suffix of object files: cannot compile". 顺便说一句,使用“-with-gmp”和“with-mpfr”和“./configure”给了我“configure:error:无法计算目标文件的后缀:无法编译”。 Hence I downloaded the srcs of gmp and mpfr and then created the soft link to it from within gcc src top leve dir 因此我下载了gmp和mpfr的srcs,然后从gcc src top leve dir中创建了它的软链接

After trying to install GCC dependencies including GMP, MPFR and MPC. 尝试安装GCC依赖项后,包括GMP,MPFRMPC。 I ran into additional install requirements, Errors and missing files; 我遇到了额外的安装要求,错误和丢失的文件; such as gmp.h header file required by MPFR to install. 比如MPFR安装所需的gmp.h头文件。 There are quit a number of issues you will run into in the process. 您将在此过程中遇到许多问题。 However, There is an Easier way to Build and Install GCC-X.0.0 or later version with an automatic linking . 但是,通过自动链接可以更轻松地构建和安装GCC-X.0.0更高版本。

OPTION ONE. 选项一。

To save the trouble of Building with make, make install and Linking the dynamic libraries, Simply: 为了省去使用make构建的问题,make install和链接动态库,简单地说:

  • Download your GCC-X.0.0 -version (with latest version from: https://gcc.gnu.org/ ) 下载您的GCC-X.0.0 -version(最新版本来自: https ://gcc.gnu.org/)
  • Extract the gcc-X-000.tar.gz files to a location /somepath/. 将gcc-X-000.tar.gz文件解压缩到某个位置/ somepath /。
  • Once you have Extracted .tar.gz file, run ./contrib/download_prerequisites script which is located on /somepath/ or the source directory. 获得Extracted .tar.gz文件后,运行位于/ somepath /或源目录的./contrib/download_prerequisites脚本。
  • This script will download support libraries including: GMP, MPFR and MPC and will create a Symlinks for you, that will BUILD all gcc dependencies automatically as part of gcc Installation process. 此脚本将下载支持库,包括: GMP,MPFRMPC ,并将为您创建一个Symlinks ,它将自动 构建所有gcc依赖项,作为gcc安装过程的一部分。

    No need to Build and Link support libraries that were downloaded to /somepath/ by issuing Make, Make Install or running ./configure file or adding links such as --with-gmp=/gmp_path/.../....., --with-mpfr=/mpfr_path/.../... because this was done when you ran script that created symlinks . 无需通过发出Make,Make Install或运行./configure文件或添加诸如--with-gmp = / gmp_path / ... / .....之类的链接来构建和链接下载到/ somepath /的支持库。 , - with-mpfr = / mpfr_path / ... / ...因为这是在运行创建符号链接的脚本时完成的。

OPTION TWO. 选项二。

  • Use your OS Package management system to install the support libraries in standard system location. 使用OS软件包管理系统在标准系统位置安装支持库。 For Debian based system including Ubuntu, Install libgmp-dev, libmpfr-dev and libmpc-dev packages. 对于基于Debian的系统,包括Ubuntu,安装libgmp-dev,libmpfr-devlibmpc-dev软件包。 For RPM based system including Fedora and SUSE, install gmp-devel, and libmpc-devel ( mpc-devel on SUSE) packages. 对于包括Fedora和SUSE在内的基于RPM的系统,请安装gmp-devellibmpc-devel (在SUSE上使用mpc-devel )软件包。
  • This option will install libraries and header files in a standard system directory where they will be found automically when building GCC. 此选项将库和头文件安装在标准系统目录中,在构建GCC时将自动找到它们。
  • This is the advantage of OS Package installation Management when you invoke "sudo apt-get install libgmp-dev" or "sudo apt-get install libmpfr-dev" install and linking is done for you. 当您调用“sudo apt-get install libgmp-dev”“sudo apt-get install libmpfr-dev”安装并完成链接时,这是OS Package安装管理的优势。 In addition, you don`t have to build the support libraries with Make, Make install or ./configure. 此外,您不必使用Make,Make install./configure构建支持库 Plus, the process takes a few minutes to complete the all process. 此外,该过程需要几分钟才能完成所有过程。
  • Now you can proceed on with GCC Installation. 现在您可以继续进行GCC安装。

CONFIGURATION: 组态:

This is the GCC config Process, with gcc-X-000.tar.gz 

Issue: 问题:

tar -xvf gcc-X-000.tar.gz 
cd gcc-X-000
./contrib/download_prerequisites
cd ..
mkdir objdir
/../gcc-X-000/configure --prefix=$HOME/gcc-X-000 --enable-languages=c,c++,fortran,go --disable-multilib
make -j 2
make install

NB: 注意:

--enable-languages such as c++ or c. - 启用语言 ,如c ++或c。

--disable-multilib ; --disable-multilib ; disable multilib based on your system and OS, you will be prompted about multilib to proceed. 根据您的系统和操作系统禁用multilib,系统将提示您继续执行multilib。

Make will take long time to complete. 制作需要很长时间才能完成。 However, you can issue the option -j #no_pro. 但是,您可以发出选项-j #no_pro。 This will run Make concurrently in parallel based on the number of processors on your PC or Mac. 这将根据PC或Mac上的处理器数量并行运行Make并行。

For detailed information on how to execute this process you can visit: https://gcc.gnu.org/wiki/InstallingGCC . 有关如何执行此过程的详细信息,请访问: https//gcc.gnu.org/wiki/InstallingGCC

I followed the top accepted answer by joelparkerhenderson. 我跟随了joelparkerhenderson最受欢迎的答案。 This is the best answer that I could find for installing on a *NIX system over the internet. 这是我通过互联网在* NIX系统上安装的最佳答案。

For posterity I want to add that if you get an error like "install error: cannot compute suffix of object files: cannot compile" 对于后代,我想补充一点,如果你得到一个错误,如“安装错误:无法计算目标文件的后缀:无法编译”

then update your LD_LIBRBARY_PATH with /tmp/gcc/lib (See joelparkerhenderson's full answer for context) 然后用/ tmp / gcc / lib更新你的LD_LIBRBARY_PATH(参见joelparkerhenderson的完整答案)

/tmp/gcc/lib contains all the required mpfr/mpc/gmp so files and the run time linker cannt find them unless you add them to LD_LIBRARY_PATH. / tmp / gcc / lib包含所有必需的mpfr / mpc / gmp文件,运行时链接器无法找到它们,除非您将它们添加到LD_LIBRARY_PATH。 Also dont forget to export LD_LIBRARY_PATH ;). 也不要忘记导出LD_LIBRARY_PATH;)。 More context here: https://gcc.gnu.org/wiki/FAQ#configure_suffix 更多上下文: https//gcc.gnu.org/wiki/FAQ#configure_suffix

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM