나는 CentOs 5 머신을 사용합니다 gcc 4.1.2
. 몇 가지 C++14 기능을 시험해보고 싶고 설치하고 싶습니다.gcc 5
기본 위치가 아닌 위치에 있습니다. 이에 접근하는 가장 좋은 방법은 무엇입니까?
예를 들어 gcc 4.7 또는 4.8의 경우 다음 질문과 답변은 다음과 같습니다. CentOS에 gcc 4.7.x/4.8.x를 설치하는 방법도움이됩니다. 그런 접근 방식에서는 최신인 것 같습니다.Redhat 개발자 도구 세트, v 3.1 베타, gcc 4.9.2가 있습니다.
[PS: CentOs 버전을 변경하는 것은 나에게 선택 사항이 아닙니다.]
답변1
CentOS 5에는 GCC-5를 설치하는 것이 불가능하다고 생각합니다. 해당 glibc
버전(2.5)이 너무 오래되었습니다.
CentOS 6의 경우 다음 지침을 따르세요.
- http://en.librehat.com/blog/build-gcc-5-dot-2-on-rhel-6/
- http://www.linuxfromscratch.org/blfs/view/cvs/general/gcc.html
또는 다음 Dockerfile과 함께 Docker를 사용할 수 있습니다.
FROM centos:centos6
RUN yum install -y gcc gcc-c++ wget xz libgcc glibc-devel glibc-headers
# Run some tests
RUN gcc --version && \
g++ --version && \
which gcc && \
which g++
RUN mkdir ~/tests && \
cd ~/tests && \
echo '#include <iostream>' > main.cpp && \
echo 'using namespace std;' >> main.cpp && \
echo 'int main() {' >> main.cpp && \
echo ' cout << "Hello world!" << endl;' >> main.cpp && \
echo ' return 0;' >> main.cpp && \
echo '}' >> main.cpp && \
g++ main.cpp -o main && \
./main
# Download and compile GCC-5
# http://en.librehat.com/blog/build-gcc-5-dot-2-on-rhel-6/
# Download and extract source code
ENV gcc_version "5.3.0"
RUN wget --no-verbose \
http://ftpmirror.gnu.org/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2 && \
tar xf gcc-${gcc_version}.tar.bz2
RUN wget --no-verbose \
https://gmplib.org/download/gmp/gmp-6.1.0.tar.xz && \
tar xf gmp-6.1.0.tar.xz && \
mv gmp-6.1.0 gcc-${gcc_version}/gmp
RUN wget --no-verbose \
ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz && \
tar xf mpc-1.0.3.tar.gz && \
mv mpc-1.0.3 gcc-${gcc_version}/mpc
RUN wget --no-verbose \
http://www.mpfr.org/mpfr-current/mpfr-3.1.4.tar.xz && \
tar xf mpfr-3.1.4.tar.xz && \
mv mpfr-3.1.4 gcc-${gcc_version}/mpfr
# Compile and install GCC
# "we highly recommend that GCC be built into a separate directory from the sources which does not reside within the source tree"
RUN mkdir gcc-${gcc_version}_build && \
cd gcc-${gcc_version}_build && \
../gcc-${gcc_version}/configure \
--prefix=/usr \
--disable-multilib \
--enable-languages=c,c++ \
--enable-libstdcxx-threads \
--enable-libstdcxx-time \
--enable-shared \
--enable-__cxa_atexit \
--disable-libunwind-exceptions \
--disable-libada \
--host x86_64-redhat-linux-gnu \
--build x86_64-redhat-linux-gnu \
--with-default-libstdcxx-abi=gcc4-compatible
RUN cd gcc-${gcc_version}_build && make -j4
RUN cd gcc-${gcc_version}_build && make install
# Validate the installed compiler
RUN hash -r && \
gcc --version && \
g++ --version && \
which gcc && \
which g++
# Register new libraries with `ldconfig`
RUN echo "/usr/local/lib64" > usrLocalLib64.conf && \
mv usrLocalLib64.conf /etc/ld.so.conf.d/ && \
ldconfig
# Clean out all the garbage
RUN rm -rf ~/${gcc_release} ~/{gcc_release}_build ~/tests