x86_64-linux-musl-g++: fatal error: cannot execute ‘cc1plus’: execvp: No such file or directory, on alpine container

  alpine, c++, docker, linux, musl

I am having a problem compiling C/C++ code on an alpine (and ubuntu) container with MUSL toolchain (http://musl.cc/x86_64-linux-musl-cross.tgz )

The error is seen when the container is run on a CentOS workstation (and also Ubuntu)

[[email protected] ~]# uname -a
Linux centoshost 3.10.0-957.12.1.el7.x86_64 #1 SMP Mon Apr 29 14:59:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.6.1810 (Core)
Release:        7.6.1810
Codename:       Core
[[email protected] ~]#

The same container image when run on an Ubuntu 18.04/CentOS 7 VM (Oracle VirtualBox) is able to compile. The docker version is same (18.09.5) on VM and the workstation.

The error:

bash-5.1# /x86_64-linux-musl-cross/bin/x86_64-linux-musl-g++ -v test.cpp
Using built-in specs.
COLLECT_GCC=/x86_64-linux-musl-cross/bin/x86_64-linux-musl-g++
Target: x86_64-linux-musl
Configured with: ../src_gcc/configure --enable-languages=c,c++,fortran CC='gcc -static --static' CXX='g++ -static --static' FC='gfortran -static --static' CFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels' CXXFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels' FFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels' LDFLAGS='-s -static --static' --enable-default-pie --enable-static-pie --disable-bootstrap --disable-assembly --disable-werror --target=x86_64-linux-musl --prefix= --libdir=/lib --disable-multilib --with-sysroot=/x86_64-linux-musl --enable-tls --disable-libmudflap --disable-libsanitizer --disable-gnu-indirect-function --disable-libmpx --enable-libstdcxx-time=rt --enable-deterministic-archives --enable-libstdcxx-time --enable-libquadmath --enable-libquadmath-support --disable-decimal-float --with-build-sysroot=/tmp/m1032/build/local/x86_64-linux-musl/obj_sysroot AR_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/ar AS_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/gas/as-new LD_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/ld/ld-new NM_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/nm-new OBJCOPY_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/objcopy OBJDUMP_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/objdump RANLIB_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/ranlib READELF_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/readelf STRIP_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/strip-new --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu 'CC_FOR_BUILD=cc -static --static' 'CXX_FOR_BUILD=g++ -static --static'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.1 20210116 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 cc1plus -quiet -v -iprefix /x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/10.2.1/ -isysroot /x86_64-linux-musl-cross/bin/../x86_64-linux-musl -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version -o /tmp/ccDckJiL.s
x86_64-linux-musl-g++: fatal error: cannot execute ‘cc1plus’: execvp: No such file or directory
compilation terminated.

I also tried adding the path to cc1plus to PATH env variable. For this i got a different error:

bash-5.1# PATH=$PATH:/x86_64-linux-musl-cross/libexec/gcc/x86_64-linux-musl/10.2.1/
bash-5.1# /x86_64-linux-musl-cross/bin/x86_64-linux-musl-g++ -v test.cpp
Using built-in specs.
COLLECT_GCC=/x86_64-linux-musl-cross/bin/x86_64-linux-musl-g++
Target: x86_64-linux-musl
Configured with: ../src_gcc/configure --enable-languages=c,c++,fortran CC='gcc -static --static' CXX='g++ -static --static' FC='gfortran -static --static' CFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels' CXXFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels' FFLAGS='-g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels' LDFLAGS='-s -static --static' --enable-default-pie --enable-static-pie --disable-bootstrap --disable-assembly --disable-werror --target=x86_64-linux-musl --prefix= --libdir=/lib --disable-multilib --with-sysroot=/x86_64-linux-musl --enable-tls --disable-libmudflap --disable-libsanitizer --disable-gnu-indirect-function --disable-libmpx --enable-libstdcxx-time=rt --enable-deterministic-archives --enable-libstdcxx-time --enable-libquadmath --enable-libquadmath-support --disable-decimal-float --with-build-sysroot=/tmp/m1032/build/local/x86_64-linux-musl/obj_sysroot AR_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/ar AS_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/gas/as-new LD_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/ld/ld-new NM_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/nm-new OBJCOPY_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/objcopy OBJDUMP_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/objdump RANLIB_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/ranlib READELF_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/readelf STRIP_FOR_TARGET=/tmp/m1032/build/local/x86_64-linux-musl/obj_binutils/binutils/strip-new --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu 'CC_FOR_BUILD=cc -static --static' 'CXX_FOR_BUILD=g++ -static --static'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.1 20210116 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 cc1plus -quiet -v -iprefix /x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/10.2.1/ -isysroot /x86_64-linux-musl-cross/bin/../x86_64-linux-musl -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version -o /tmp/ccogMFKi.s
GNU C++14 (GCC) version 10.2.1 20210116 (x86_64-linux-musl)
        compiled by GNU C version 10.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include/c++/10.2.1"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include/c++/10.2.1/x86_64-linux-musl"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include/c++/10.2.1/backward"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/10.2.1/include"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include/c++/10.2.1"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include/c++/10.2.1/x86_64-linux-musl"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include/c++/10.2.1/backward"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../x86_64-linux-musl/usr/local/include"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/10.2.1/../../../../x86_64-linux-musl/include"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../x86_64-linux-musl/usr/include"
ignoring nonexistent directory "/x86_64-linux-musl-cross/bin/../lib/gcc/../../lib/gcc/x86_64-linux-musl/10.2.1/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
cc1plus: fatal error: test.cpp: Operation not permitted
compilation terminated.

I am running as root and ‘test.cpp’ has 644 permissions.

Source: Windows Questions C++

LEAVE A COMMENT