developer tip

공유 라이브러리없이 GMP, MPFR, MPC, ELF를 사용하여 GCC를 개별적으로 설치하는 방법은 무엇입니까?

optionbox 2020. 7. 28. 08:25
반응형

공유 라이브러리없이 GMP, MPFR, MPC, ELF를 사용하여 GCC를 개별적으로 설치하는 방법은 무엇입니까?



패키지 관리자 (예 : yum, rpm, apt, dpkg)를 사용하지 않고 공유 라이브러리를 사용하지 않고 올바른 버전의 종속성을 사용하여 현재 버전을 사용하여 GCC (GNU Compiler Collection)를 개별적으로 설치하려면 어떻게해야 합니까?

일반적인 개발자는 GCC를 일반적인 방식으로 설치하거나 패키지 관리자 (yum, rpm, apt, dpkg, port, brew 등)를 사용하거나 여기의 지침을 따르고 싶을 것입니다 ( http://gcc.gnu.org/wiki/ GCC 설치 ).

내 질문은 공유 라이브러리없이 GCC를 하나씩 설치하는 방법입니다.

  • 공유 라이브러리를 사용하지 않고 공유 라이브러리를 만들지 않고 시스템 내에서 이동할 수있는 완전히 독립적 인 GCC를 원합니다.
  • 이것이 GCC가 "어려운 방법"이라고 부르는 것이며 일반적인 사용자에게는 권장되지 않습니다.

GCC는 다음에 의존합니다.

  • GMP : GNU 다중 정밀도 산술 라이브러리
  • MPFR : GNU 다중 정밀도 부동 소수점 반올림 라이브러리
  • MPC : GNU 다중 정밀도 C 라이브러리
  • ELF : 실행 가능하고 링크 가능한 형식 라이브러리
  • PPL : Parma Polyhedra Library (메모리 최적화를위한 선택적)

쉬운 길

일반적인 개발자 인 경우 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

어려운 방법

GCC는 여기에 대한 대답은 모든 것을 한 조각 씩 만들고 공유 라이브러리를 사용하지 않기 때문에 "어려운 방법"이라고 말합니다.

GCC 인프라

GCC 인프라 확보 :

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

임시 디렉토리에 다운로드를 넣습니다 (원하는 디렉토리를 사용할 수 있음).

/opt/downloads

downloads 디렉토리 또는 해당 서브 디렉토리와 다른 temp 디렉토리에 인프라를 빌드하십시오.

/tmp/gcc

다음과 같은 정적 라이브러리를 사용하여 인프라를 구성하십시오.

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

--disable-shared 플래그는 필요에 따라 자세히 살펴볼 가치가 있습니다. 정적 코드 만 작성하기 때문에 --disable-shared를 사용하고 공유 코드를 작성하지 않기를 원합니다. 필자는 GCC를 드라이브 주변으로 쉽게 옮기는 것이 필요하므로 모든 정적 코드를 원하고 공유 코드를 원하지 않습니다. 공유 코드를 선호하는 경우 --disable-shared 플래그를 생략하십시오.

버전

이 답변의 명령을 실행할 때 필요에 맞는 현재 GCC 버전 번호를 사용하도록 명령을 업데이트하십시오. 이 답변의 명령은 GCC 4.6.2 용입니다.

GCC 문서에 따르면, "필요한 도구의 새로운 버전이 일반적으로 작동하지만 일반적으로 라이브러리 요구 사항이 더 엄격합니다. 경우에 따라 최신 버전이 작동 할 수도 있지만 문서화 된 정확한 버전을 사용하는 것이 더 안전합니다."

GMP

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은 GNU 다중 정밀도 부동 소수점 반올림 라이브러리입니다. 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는 GNU 다중 정밀도 C 라이브러리입니다. 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는 Executable and Linkable Format의 약어입니다. 이 라이브러리는 아키텍처 독립적 인 크기와 엔디안 지원을 제공합니다.

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는 GNU 컴파일러 모음입니다. 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

동일한 마운트 지점의 스크래치 디렉토리에 gcc를 빌드하십시오. (/ tmp 내에 빌드하면 크로스 컴파일 호스트 문제가 발생합니다)

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

configure 명령과 해당 플래그는 모두 하나의 명령 행에 있어야합니다 (이 게시물은 웹 페이지 너비 때문에 별도의 행에 표시됨).

참고 : 전체 경로를 사용하여 라이브러리 경로 환경 변수를 구성하고 설정하지 않습니다. 부트 스트랩을 비활성화하고 공유 라이브러리를 원하지 않기 때문에 (일반 사용자는 둘 다 원할 수 있음) posix 스레드를 사용하고 원하는 기본 플래그를 사용하도록 선택합니다 (일반 사용자는 다른 스레드를 사용하거나 건너 뛰기를 원할 수 있음) 기본 플래그). 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

이 페이지는 GCC 설치 정보, 빌드 방법, 다양한 플래그 등에 유용합니다.

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

업데이트

ppl 라이브러리는 메모리 최적화에 사용될 수 있습니다 : bugseng.com/products/ppl/Download를 참조하십시오 (폴의 의견에 감사합니다)

gcc 소스 디렉토리에서 ./contrib/download_prerequisites를 실행할 수 있습니다. (reddit에서 N7P에 감사합니다)


허용되는 답변은 필요보다 훨씬 복잡하며 모든 버전에 맞는 것은 아닙니다. GCC를 구축하는 --disable-shared것은 일반적으로 매우 나쁜 생각입니다. 보다 쉬운 방법 http://gcc.gnu.org/wiki/InstallingGCC참조하십시오 .

전체 과정은 (당신이 구축하려는 버전 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

(그러나 어쨌든 위의 링크를 읽으십시오. 유용한 정보가 들어 있습니다.)

분명히 우분투의 일부 사람들은 GCC 빌드 프로세스를 방해하는 환경에 엄청난 쓰레기 세트가 있으며 먼저 제거해야합니다.

unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE LD_LIBRARY_PATH

나는 클러스터에서 일합니다. 마스터 노드 만 인터넷에 연결되어 있습니다. 노드의 소프트웨어가 오래되어 일반적으로 유지 관리되지 않습니다. 루트 액세스 권한이 없습니다. 두 가지 옵션이 있습니다.

  • 필요한 정적 소프트웨어 빌드 (계산 패키지); 또는
  • 정적 컴파일러를 빌드하십시오.

나는 두 번째를 선택하고 gcc, g ++ 및 gfortran을 만들었습니다.

나는 모든 것을 만들었습니다.

PREFIX=$HOME/cmp/soft/sft

과에 대한 make내가 사용

THREADS=8

아래에서 gcc는

  • GMP
  • MPFR
  • MPC
  • ISL
  • 클러치

ftp://gcc.gnu.org/pub/gcc/releases 에서 최신 gcc를 얻을 수 있습니다.

종속성은 ftp://gcc.gnu.org/pub/gcc/infrastructure에 있습니다.

의존성

다음 스크립트를 사용하여 종속성을 얻습니다.

#!/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

다음과 같은 bash 함수가 사용됩니다.

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

아래의 각 명령은 방금 다운로드 한 lib의 디렉토리에 발행됩니다.

GMP

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

MPFR

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

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

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

클러치

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

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")

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". Hence I downloaded the srcs of gmp and mpfr and then created the soft link to it from within gcc src top leve dir


After trying to install GCC dependencies including GMP, MPFR and MPC. I ran into additional install requirements, Errors and missing files; such as gmp.h header file required by MPFR to install. 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.

OPTION ONE.

To save the trouble of Building with make, make install and Linking the dynamic libraries, Simply:

  • Download your GCC-X.0.0 -version (with latest version from: https://gcc.gnu.org/)
  • Extract the gcc-X-000.tar.gz files to a location /somepath/.
  • Once you have Extracted .tar.gz file, run ./contrib/download_prerequisites script which is located on /somepath/ or the source directory.
  • 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.

    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.

OPTION TWO.

  • Use your OS Package management system to install the support libraries in standard system location. For Debian based system including Ubuntu, Install libgmp-dev, libmpfr-dev and libmpc-dev packages. For RPM based system including Fedora and SUSE, install gmp-devel, and libmpc-devel(mpc-devel on SUSE) packages.
  • This option will install libraries and header files in a standard system directory where they will be found automically when building 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. In addition, you don`t have to build the support libraries with Make, Make install or ./configure. Plus, the process takes a few minutes to complete the all process.
  • Now you can proceed on with GCC Installation.

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.

--disable-multilib; disable multilib based on your system and OS, you will be prompted about multilib to proceed.

Make will take long time to complete. However, you can issue the option -j #no_pro. This will run Make concurrently in parallel based on the number of processors on your PC or Mac.

For detailed information on how to execute this process you can visit: https://gcc.gnu.org/wiki/InstallingGCC.


I followed the top accepted answer by joelparkerhenderson. This is the best answer that I could find for installing on a *NIX system over the internet.

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 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. Also dont forget to export LD_LIBRARY_PATH ;). More context here: https://gcc.gnu.org/wiki/FAQ#configure_suffix

참고URL : https://stackoverflow.com/questions/9450394/how-to-install-gcc-piece-by-piece-with-gmp-mpfr-mpc-elf-without-shared-libra

반응형