Tuesday, November 16, 2021

[SOLVED] How to ./configure or make with multiple GCC versions installed?

Issue

Question

Among other things, I have the following in a Dockerfile, which installs gcc 5.3.1 and gcc 6.3.1:

FROM centos:7

RUN yum install deltarpm -y && \
    yum install -y \
        centos-release-scl \
        epel-release && \
    yum install -y \
        devtoolset-4-gcc*-5.3.1 \
        devtoolset-6-gcc*-6.3.1 \
        glibc-*-2.17

When I execute ./configure, make or similar, what is the proper approach to define which GCC version to be used?


What I have tried

When I just had one devtoolset/GCC version installed, I successfully built by setting PATH, CC, CXX environment variables prior to executing ./configure or make:

# gcc 6.3.1
ENV PATH="/opt/rh/devtoolset-6/root/usr/bin:${PATH}"
ENV CC=/opt/rh/devtoolset-6/root/usr/bin/gcc
ENV CXX=/opt/rh/devtoolset-6/root/usr/bin/g++

RUN \
    cd app1 && \
    ./configure && \
    gmake && \
    gmake install

And when having both GCC versions installed, I now tried this (with unsuccessful results):

ENV original_path="${PATH}"

# gcc 6.3.1
ENV PATH="/opt/rh/devtoolset-6/root/usr/bin:${original_path}"
ENV CC=/opt/rh/devtoolset-6/root/usr/bin/gcc
ENV CXX=/opt/rh/devtoolset-6/root/usr/bin/g++

RUN \
    cd app1 && \
    ./configure && \
    gmake && \
    gmake install

# gcc 5.3.1
ENV PATH="/opt/rh/devtoolset-4/root/usr/bin:${original_path}"
ENV CC=/opt/rh/devtoolset-4/root/usr/bin/gcc
ENV CXX=/opt/rh/devtoolset-4/root/usr/bin/g++

RUN \
    cd app2 && \
    ./configure && \
    gmake && \
    gmake install

The (partial) error (from building Qt4 from source):

/opt/rh/devtoolset-4/root/usr/bin/g++ -c -pipe -O2 -I/usr/include/freetype2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DQT_SHARED -DQT_BUILD_OPENGL_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_HAVE_SSE3 -DQT_HAVE_SSSE3 -DQT_HAVE_SSE4_1 -DQT_HAVE_SSE4_2 -DQT_HAVE_AVX -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I../../mkspecs/linux-g++ -I. -I../../include/QtCore -I../../include/QtGui -I../../include -I../../include/QtOpenGL -I.rcc/release-shared -I/usr/include/freetype2
-I../3rdparty/harfbuzz/src -I/usr/X11R6/include -I/usr/X11R6/include -I.moc/release-shared -o .obj/release-shared/qgl2pexvertexarray.o gl2paintengineex/qgl2pexvertexarray.cpp
/opt/rh/devtoolset-4/root/usr/bin/g++ -c -pipe -O2 -I/usr/include/freetype2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DQT_SHARED -DQT_BUILD_OPENGL_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_HAVE_SSE3 -DQT_HAVE_SSSE3 -DQT_HAVE_SSE4_1 -DQT_HAVE_SSE4_2 -DQT_HAVE_AVX -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I../../mkspecs/linux-g++ -I. -I../../include/QtCore -I../../include/QtGui -I../../include -I../../include/QtOpenGL -I.rcc/release-shared -I/usr/include/freetype2
-I../3rdparty/harfbuzz/src -I/usr/X11R6/include -I/usr/X11R6/include -I.moc/release-shared -o .obj/release-shared/qpaintengineex_opengl2.o gl2paintengineex/qpaintengineex_opengl2.cpp
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
gmake[1]: *** [.obj/release-shared/qglgradientcache.o] Error 4
gmake[1]: *** Waiting for unfinished jobs....
gmake[1]: *** [.obj/release-shared/qglengineshadermanager.o] Error 4
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
gmake[1]: *** [.obj/release-shared/qpaintengineex_opengl2.o] Error 4
gmake[1]: Leaving directory `/workdir/qt/src/opengl'
gmake: *** [sub-opengl-make_default-ordered] Error 2

I also tried this, but this still doesn't work:

# Custom environment variables
ENV original_path="${PATH}"
ENV path_gcc531="/opt/rh/devtoolset-4/root/usr/bin:${original_path}"
ENV cc_gcc531=/opt/rh/devtoolset-4/root/usr/bin/gcc
ENV cxx_gcc531=/opt/rh/devtoolset-4/root/usr/bin/g++
ENV path_gcc631="/opt/rh/devtoolset-6/root/usr/bin:${original_path}"
ENV cc_gcc631=/opt/rh/devtoolset-6/root/usr/bin/gcc
ENV cxx_gcc631=/opt/rh/devtoolset-6/root/usr/bin/g++

RUN \
    cd app1 && \
    # gcc 6.3.1
    PATH="${path_gcc631}" CC="${cc_gcc631}" CXX="${cxx_gcc631}" ./configure && \
    PATH="${path_gcc631}" CC="${cc_gcc631}" CXX="${cxx_gcc631}" gmake && \
    PATH="${path_gcc631}" CC="${cc_gcc631}" CXX="${cxx_gcc631}" gmake install

RUN \
    cd app2 && \
    # gcc 5.3.1
    PATH="${path_gcc531}" CC="${cc_gcc531}" CXX="${cxx_gcc531}" ./configure && \
    PATH="${path_gcc531}" CC="${cc_gcc531}" CXX="${cxx_gcc531}" gmake && \
    PATH="${path_gcc531}" CC="${cc_gcc531}" CXX="${cxx_gcc531}" gmake install

This generates seemingly random errors during some builds which didn't appear prior to introducing more than one devtools/gcc install into the mix.

From what I understand, one should be able to have multiple gcc installations on the same system: https://gcc.gnu.org/faq.html#multiple
- So what am I doing wrong here?


Solution

Turns out this worked:

FROM centos:7.3.1611

RUN yum install deltarpm -y && \
    yum install -y \
        centos-release-scl \
        epel-release && \
    yum install -y \
        # gcc 5.3.1 (via Devtools which is equivalent of RedHat DTS)
            devtoolset-4-gcc*-5.3.1 \
            make \
        # gcc 6.3.1 (via Devtools which is equivalent of RedHat DTS)
            devtoolset-6-gcc*-6.3.1 \
            devtoolset-6-make* \
        # glibc 2.17
            glibc-*-2.17

RUN \
    cd app1 && \
    # gcc 6.3.1
    scl enable devtoolset-6 './configure' && \
    scl enable devtoolset-6 'gmake' && \
    scl enable devtoolset-6 'gmake install'

RUN \
    cd app2 && \
    # gcc 5.3.1
    scl enable devtoolset-4 './configure' && \
    scl enable devtoolset-4 'gmake' && \
    scl enable devtoolset-4 'gmake install'


Answered By - fredrik