I just built boost - and the output is sat on my desktop - boost

I followed these instructions from github to clone and build the boost libraries.
https://github.com/boostorg/boost/wiki/Getting-Started
The end of the ./b2 command tells me
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/user/Desktop/boost
The following directory should be added to linker library paths:
/home/user/Desktop/boost/stage/lib
What should I do with these folders? I would like to put boost in the "regular place it should go in order for gcc to see it".
This is probably /usr/include ? Is it safe for me to move the folder boost to this location? What about the boost/stage/lib folder. Where does this go?
gcc -v /dev/null -o /dev/null
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 6.3.1 20161221 (Red Hat 6.3.1-1) (GCC)
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/6.3.1/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/6.3.1/:/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' '/dev/null' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/6.3.1/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper -plugin-opt=-fresolution=/tmp/cce2dq2i.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /dev/null /usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/6.3.1/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/6.3.1 -L/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../.. /dev/null -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/6.3.1/crtend.o /usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64/crtn.o
/dev/null: file not recognized: File truncated
collect2: error: ld returned 1 exit status

I would like to put boost in the "regular place it should go in order for gcc to see it".
For gcc run cpp -v /dev/null -o /dev/null. In its output there are include search directories and LIBRARY_PATH with a list of library search directories. These are the regular places. Copying the headers and libraries into the regular places normally requires root permissions.
Alternatively, use -I/home/user/Desktop/boost extra command line option when compiling and -L/home/user/Desktop/boost/stage/lib -Wl,-rpath=/home/user/Desktop/boost/stage/lib when linking to use it from the current location.
Another way to build boost (and other 3rd-party libraries) is to have it installed in a separate directory, e.g. /usr/local with versioned directories, e.g. /usr/local/boost-1.60.0.
To build boost into /usr/local/boost-1.60.0 do the following commands in bash:
$ cd boost-1.60.0 # The directory with boost sources.
$ JOBS=8
$ PREFIX=/usr/local/boost-1.60.0
$ mkdir -p ${PREFIX}
$ ./bootstrap.sh --prefix=${PREFIX} --libdir=${PREFIX}/lib64
$ B2FLAGS="-j${JOBS} --layout=system --disable-icu variant=release link=shared threading=multi runtime-link=shared linkflags=-Wl,-rpath,${PREFIX}/lib64 boost.locale.icu=off boost.locale.iconv=on"
$ ./b2 ${B2FLAGS}
$ ./b2 ${B2FLAGS} install
The linkflags=-Wl,-rpath,${PREFIX}/lib64 bit makes sure that when you run your application boost shared libraries that depend on other boost shared libraries find them in that ${PREFIX}/lib64 directory.
And then use the following flags when builing your applications with boost you just built:
Flags for compiling (CPPFLAGS): -I/usr/local/boost-1.60.0/include.
Flags for linking (LDFLAGS): -L/usr/local/boost-1.60.0/lib64 -Wl,-rpath=/usr/local/boost-1.60.0/lib64.

Related

Build RocksDB static library using vcpkg and custom gcc on Windows

I am trying to create Kotlin/Native bindings for RocksDB. This requires that RocksDB is compiled using gcc and g++ version 9.2.0, because that is the only version that Kotlin/Native supports. If I build using 9.5.0 or later, then I get errors:
const: error: undefined reference to 'gettid'
The gettid wrapper was added to glibc 2.30, but Kotlin/Native uses glibc 2.15 when linking.
Since RocksDB has a Makefile that works on Linux and macOS, I am able to successfully build compatible RocksDB libraries. However, I am encountering problems when trying to build RocksDB on Windows.
The RocksDB wiki explains how to use vcpkg to build RocksDB on Windows, which is quite easy. However, vcpkg will use the system gcc, unless specially instructed otherwise using a special toolchain cmake file.
Updating vcpkg to use gcc 9.2.0
vcpkg will accept a custom cmake toolchain file where the location of gcc and g++ can be defined, so I have created that file:
# D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/konan-toolchain.cmake
set(CMAKE_C_COMPILER "C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/g++.exe")
set(CMAKE_VERBOSE_MAKEFILE ON)
And then set the file location using the VCPKG_CHAINLOAD_TOOLCHAIN_FILE property in the vcpkg triplet file I use to build RocksDB on Windows:
echo "set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE \"D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/konan-toolchain.cmake\")" \
>> ./triplets/community/x64-mingw-static.cmake
vcpkg install fails - "not able to compile a simple test program"
vcpkg seems to be correctly set up to use Kotlin/Native's gcc 9.2.0, but the vcpkg install fails:
Detecting compiler hash for triplet x64-windows...
Detecting compiler hash for triplet x64-mingw-static...
error: while detecting compiler information:
The log file content at "D:\a\kotlin-on-the-rocksdb\kotlin-on-the-rocksdb\vcpkg\buildtrees\detect_compiler\stdout-x64-mingw-static.log" is:
-- Found external ninja('1.10.2').
-- Configuring x64-mingw-static
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:112 (message):
Command failed: C:/ProgramData/chocolatey/bin/ninja.exe -v
Working Directory: D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/vcpkg-parallel-configure
Error code: 1
See logs for more information:
D:\a\kotlin-on-the-rocksdb\kotlin-on-the-rocksdb\vcpkg\buildtrees\detect_compiler\config-x64-mingw-static-rel-CMakeCache.txt.log
D:\a\kotlin-on-the-rocksdb\kotlin-on-the-rocksdb\vcpkg\buildtrees\detect_compiler\config-x64-mingw-static-out.log
Call Stack (most recent call first):
scripts/cmake/vcpkg_configure_cmake.cmake:310 (vcpkg_execute_required_process)
scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
scripts/ports.cmake:147 (include)
error: vcpkg was unable to detect the active compiler's information. See above for the CMake failure output.
Error: Process completed with exit code 1.
The log file contains more details:
[1/1] "C:/Program Files/CMake/bin/cmake.exe" -E chdir ".." "C:/Program Files/CMake/bin/cmake.exe" "D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/scripts/detect_compiler" "-G" "Ninja" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/packages/detect_compiler_x64-mingw-static" "-DCMAKE_MAKE_PROGRAM=C:/ProgramData/chocolatey/bin/ninja.exe" "-DCMAKE_SYSTEM_NAME=MinGW" "-DBUILD_SHARED_LIBS=OFF" "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/konan-toolchain.cmake" "-DVCPKG_TARGET_TRIPLET=x64-mingw-static" "-DVCPKG_SET_CHARSET_FLAG=ON" "-DVCPKG_PLATFORM_TOOLSET=external" "-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON" "-DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE" "-DCMAKE_VERBOSE_MAKEFILE=ON" "-DVCPKG_APPLOCAL_DEPS=OFF" "-DCMAKE_TOOLCHAIN_FILE=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON" "-DVCPKG_CXX_FLAGS=" "-DVCPKG_CXX_FLAGS_RELEASE=" "-DVCPKG_CXX_FLAGS_DEBUG=" "-DVCPKG_C_FLAGS=" "-DVCPKG_C_FLAGS_RELEASE=" "-DVCPKG_C_FLAGS_DEBUG=" "-DVCPKG_CRT_LINKAGE=dynamic" "-DVCPKG_LINKER_FLAGS=" "-DVCPKG_LINKER_FLAGS_RELEASE=" "-DVCPKG_LINKER_FLAGS_DEBUG=" "-DVCPKG_TARGET_ARCHITECTURE=x64" "-DCMAKE_INSTALL_LIBDIR:STRING=lib" "-DCMAKE_INSTALL_BINDIR:STRING=bin" "-D_VCPKG_ROOT_DIR=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg" "-DZ_VCPKG_ROOT_DIR=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg" "-D_VCPKG_INSTALLED_DIR=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/vcpkg_installed" "-DVCPKG_MANIFEST_INSTALL=OFF"
FAILED: ../CMakeCache.txt
"C:/Program Files/CMake/bin/cmake.exe" -E chdir ".." "C:/Program Files/CMake/bin/cmake.exe" "D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/scripts/detect_compiler" "-G" "Ninja" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/packages/detect_compiler_x64-mingw-static" "-DCMAKE_MAKE_PROGRAM=C:/ProgramData/chocolatey/bin/ninja.exe" "-DCMAKE_SYSTEM_NAME=MinGW" "-DBUILD_SHARED_LIBS=OFF" "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/konan-toolchain.cmake" "-DVCPKG_TARGET_TRIPLET=x64-mingw-static" "-DVCPKG_SET_CHARSET_FLAG=ON" "-DVCPKG_PLATFORM_TOOLSET=external" "-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON" "-DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE" "-DCMAKE_VERBOSE_MAKEFILE=ON" "-DVCPKG_APPLOCAL_DEPS=OFF" "-DCMAKE_TOOLCHAIN_FILE=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON" "-DVCPKG_CXX_FLAGS=" "-DVCPKG_CXX_FLAGS_RELEASE=" "-DVCPKG_CXX_FLAGS_DEBUG=" "-DVCPKG_C_FLAGS=" "-DVCPKG_C_FLAGS_RELEASE=" "-DVCPKG_C_FLAGS_DEBUG=" "-DVCPKG_CRT_LINKAGE=dynamic" "-DVCPKG_LINKER_FLAGS=" "-DVCPKG_LINKER_FLAGS_RELEASE=" "-DVCPKG_LINKER_FLAGS_DEBUG=" "-DVCPKG_TARGET_ARCHITECTURE=x64" "-DCMAKE_INSTALL_LIBDIR:STRING=lib" "-DCMAKE_INSTALL_BINDIR:STRING=bin" "-D_VCPKG_ROOT_DIR=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg" "-DZ_VCPKG_ROOT_DIR=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg" "-D_VCPKG_INSTALLED_DIR=D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/vcpkg_installed" "-DVCPKG_MANIFEST_INSTALL=OFF"
System is unknown to cmake, create:
Platform/MinGW to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- The C compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
System is unknown to cmake, create:
Platform/MinGW to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/gcc.exe
System is unknown to cmake, create:
Platform/MinGW to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Check for working C compiler: C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/gcc.exe - works
-- Detecting C compile features
-- Detecting C compile features - done
-- The CXX compiler identification is unknown
-- Detecting CXX compiler ABI info
System is unknown to cmake, create:
Platform/MinGW to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/g++.exe
System is unknown to cmake, create:
Platform/MinGW to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- Check for working CXX compiler: C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/g++.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCXXCompiler.cmake:63 (message):
The C++ compiler
"C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/g++.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeScratch/TryCompile-0ck1wg
Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_8403e && [1/2] Building CXX object CMakeFiles\cmTC_8403e.dir\testCXXCompiler.cxx.obj
FAILED: CMakeFiles/cmTC_8403e.dir/testCXXCompiler.cxx.obj
C:\Users\runneradmin\.konan\dependencies\msys2-mingw-w64-x86_64-2\bin\g++.exe -o CMakeFiles\cmTC_8403e.dir\testCXXCompiler.cxx.obj -c D:\a\kotlin-on-the-rocksdb\kotlin-on-the-rocksdb\vcpkg\buildtrees\detect_compiler\x64-mingw-static-rel\CMakeFiles\CMakeScratch\TryCompile-0ck1wg\testCXXCompiler.cxx
cc1plus.exe: error: unrecognized command-line option '-auxbase-strip'
cc1plus.exe: error: too many filenames given; type 'cc1plus.exe --help' for usage
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:12 (enable_language)
-- Configuring incomplete, errors occurred!
See also "D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeOutput.log".
See also "D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeError.log".
ninja: build stopped: subcommand failed.
The log indicates that the correct gcc/g++ commands are used:
The C compiler identification is GNU 9.2.0
But it fails.
What I've tried
Increase logging
I have tried increasing the log verbosity, but I wasn't able to get more information.
set(CMAKE_VERBOSE_MAKEFILE ON)
unrecognized command-line option '-auxbase-strip'
I was only able to find that this option is internal, and shouldn't be used. I don't know where it's coming from. There's no mention of it in vcpkg.
This question mentions auxbase, but not auxbase-strip, and has no answers.
too many filenames given
The answers in this question suggest
use -O2 instead of -o2, but from what I can tell RocksDB already uses -O2
no spaces in paths - but I'm pretty sure that there aren't any...
GitHub Workflow
I am using a GitHub Workflow, so I can automate building with a Windows machine.
Here is a summary:
Checkout vcpkg
git clone --depth 1 https://github.com/microsoft/vcpkg.git
cd vcpkg
Update the cmake to be a release library (which makes the produced library much smaller) and use the custom toolchain cmake.
echo "set(VCPKG_BUILD_TYPE release)" >> ./triplets/community/x64-mingw-static.cmake
echo "set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE \"D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/konan-toolchain.cmake\")" >> ./triplets/community/x64-mingw-static.cmake
set up vcpkg, set the RocksDB version
./bootstrap-vcpkg.sh
touch vcpkg.json;
cat <<EOT >> vcpkg.json
{
"dependencies": [
"rocksdb",
"zstd",
"zlib",
"snappy",
"lz4",
"bzip2"
],
"overrides": [
{ "name": "rocksdb", "version": "${{ env.ROCKSDB_VERSION }}" }
]
}
EOT
vcpkg x-update-baseline --add-initial-baseline
vcpkg install
Additional logs
./vcpkg/buildtrees/detect_compiler/x64-windows-rel/CMakeFiles/CMakeOutput.log
The target system is: Windows - 10.0.20348 - AMD64
The host system is: Windows - 10.0.20348 - AMD64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe
Build flags: ;/nologo;/DWIN32;/D_WINDOWS;/W3;/utf-8;/MP;
Id flags:
The output was:
0
CMakeCCompilerId.c
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.exe"
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.obj"
The C compiler identification is MSVC, found in "D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-windows-rel/CMakeFiles/3.25.2/CompilerIdC/CMakeCCompilerId.exe"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe
Build flags: ;/nologo;/DWIN32;/D_WINDOWS;/W3;/utf-8;/GR;/EHsc;/MP;
Id flags:
The output was:
0
CMakeCXXCompilerId.cpp
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.exe"
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.obj"
The CXX compiler identification is MSVC, found in "D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-windows-rel/CMakeFiles/3.25.2/CompilerIdCXX/CMakeCXXCompilerId.exe"
./vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeError.log
Detecting C compiler ABI info failed to compile with the following output:
Change Dir: D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeScratch/TryCompile-oiuqqn
Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_3a862 && [1/2] Building C object CMakeFiles/cmTC_3a862.dir/CMakeCCompilerABI.c.obj
Using built-in specs.
COLLECT_GCC=C:\Users\runneradmin\.konan\dependencies\msys2-mingw-w64-x86_64-2\bin\gcc.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-9.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 9.2.0 (Rev2, Built by MSYS2 project)
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_3a862.dir/CMakeCCompilerABI.c.obj' '-c' '-mtune=generic' '-march=x86-64'
C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/cc1.exe -quiet -v -iprefix C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/ -D_REENTRANT C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeCCompilerABI.c -quiet -dumpbase CMakeCCompilerABI.c -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_3a862.dir/CMakeCCompilerABI.c.obj -version -o C:\Users\RUNNER~1\AppData\Local\Temp\ccTdIyhC.s
GNU C17 (Rev2, Built by MSYS2 project) version 9.2.0 (x86_64-w64-mingw32)
compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.21-GMP
warning: GMP header version 6.1.2 differs from library version 6.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/9.2.0/include"
ignoring nonexistent directory "C:/building/msys64/mingw64/include"
ignoring nonexistent directory "/mingw64/include"
ignoring duplicate directory "C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/9.2.0/include-fixed"
ignoring duplicate directory "C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "C:/building/msys64/mingw64/x86_64-w64-mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/include
C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../include
C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/include-fixed
C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/include
End of search list.
GNU C17 (Rev2, Built by MSYS2 project) version 9.2.0 (x86_64-w64-mingw32)
compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.21-GMP
warning: GMP header version 6.1.2 differs from library version 6.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3bcdf03344e3ad7cb057c2ec82f696e6
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_3a862.dir/CMakeCCompilerABI.c.obj' '-c' '-mtune=generic' '-march=x86-64'
C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/as.exe -v -o CMakeFiles/cmTC_3a862.dir/CMakeCCompilerABI.c.obj C:\Users\RUNNER~1\AppData\Local\Temp\ccTdIyhC.s
GNU assembler version 2.32 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.32
COMPILER_PATH=C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../lib/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_3a862.dir/CMakeCCompilerABI.c.obj' '-c' '-mtune=generic' '-march=x86-64'
[2/2] Linking C executable cmTC_3a862
Using built-in specs.
COLLECT_GCC=C:\Users\runneradmin\.konan\dependencies\msys2-mingw-w64-x86_64-2\bin\gcc.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-9.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 9.2.0 (Rev2, Built by MSYS2 project)
COMPILER_PATH=C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../lib/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/;C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../
COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_3a862.exe' '-mtune=generic' '-march=x86-64'
C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/collect2.exe -plugin C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/liblto_plugin-0.dll -plugin-opt= -plugin-opt=-fresolution=C:\Users\RUNNER~1\AppData\Local\Temp\cc5FiNtF.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic -o cmTC_3a862.exe C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/crtbegin.o -LC:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0 -LC:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc -LC:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../lib -LC:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib -LC:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../.. CMakeFiles/cmTC_3a862.dir/CMakeCCompilerABI.c.obj -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/Users/runneradmin/.konan/dependencies/msys2-mingw-w64-x86_64-2/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/crtend.o
COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_3a862.exe' '-mtune=generic' '-march=x86-64'
Cannot copy output executable
''
to destination specified by COPY_FILE:
'D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/3.25.2/CMakeDetermineCompilerABI_C.bin'
Recorded try_compile output location doesn't exist:
D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeScratch/TryCompile-oiuqqn/cmTC_3a862
Checking whether the CXX compiler is IAR using "" did not match "IAR .+ Compiler":
g++.exe: fatal error: no input files
compilation terminated.
Checking whether the CXX compiler is IAR using "" did not match "IAR .+ Compiler":
g++.exe: fatal error: no input files
compilation terminated.
Detecting CXX compiler ABI info failed to compile with the following output:
Change Dir: D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeScratch/TryCompile-s77rm4
Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_4db65 && [1/2] Building CXX object CMakeFiles\cmTC_4db65.dir\CMakeCXXCompilerABI.cpp.obj
FAILED: CMakeFiles/cmTC_4db65.dir/CMakeCXXCompilerABI.cpp.obj
C:\Users\runneradmin\.konan\dependencies\msys2-mingw-w64-x86_64-2\bin\g++.exe -o CMakeFiles\cmTC_4db65.dir\CMakeCXXCompilerABI.cpp.obj -c "C:\Program Files\CMake\share\cmake-3.25\Modules\CMakeCXXCompilerABI.cpp"
cc1plus.exe: error: unrecognized command-line option '-auxbase-strip'
cc1plus.exe: error: too many filenames given; type 'cc1plus.exe --help' for usage
ninja: build stopped: subcommand failed.
Determining if the C++ compiler works failed with the following output:
Change Dir: D:/a/kotlin-on-the-rocksdb/kotlin-on-the-rocksdb/vcpkg/buildtrees/detect_compiler/x64-mingw-static-rel/CMakeFiles/CMakeScratch/TryCompile-552faq
Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_e2caf && [1/2] Building CXX object CMakeFiles\cmTC_e2caf.dir\testCXXCompiler.cxx.obj
FAILED: CMakeFiles/cmTC_e2caf.dir/testCXXCompiler.cxx.obj
C:\Users\runneradmin\.konan\dependencies\msys2-mingw-w64-x86_64-2\bin\g++.exe -o CMakeFiles\cmTC_e2caf.dir\testCXXCompiler.cxx.obj -c D:\a\kotlin-on-the-rocksdb\kotlin-on-the-rocksdb\vcpkg\buildtrees\detect_compiler\x64-mingw-static-rel\CMakeFiles\CMakeScratch\TryCompile-552faq\testCXXCompiler.cxx
cc1plus.exe: error: unrecognized command-line option '-auxbase-strip'
cc1plus.exe: error: too many filenames given; type 'cc1plus.exe --help' for usage
ninja: build stopped: subcommand failed.

Msys gcc produces exe that results in "cannot execute binary file: Exec format error"

On an Msys installation I use only occasionally, I could not produce a working executable with gcc. I upgraded the system with pacman -Suy but the error persists.
Here is a session transcript:
$ gcc -v array-indexing.c -o array-indexing.exe
gcc -v array-indexing.c -o array-indexing.exe
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/10.2.0/lto-wrapper.exe
Target: x86_64-pc-msys
Configured with: /c/_/S/gcc/src/gcc-10.2.0/configure --build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit --with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as --disable-isl-version-check --enable-checking=release --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-msys/10.2.0/cc1.exe -quiet -v -idirafter /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/../include/w32api -idirafter /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api array-indexing.c -quiet -dumpbase array-indexing.c -mtune=generic -march=x86-64 -auxbase array-indexing -version -o /tmp/ccHxGOyu.s
GNU C17 (GCC) version 10.2.0 (x86_64-pc-msys)
compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.1.0, MPC version 1.1.0, isl version isl-0.22.1-GMP
warning: GMP header version 6.2.0 differs from library version 6.2.1.
warning: MPC header version 1.1.0 differs from library version 1.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-msys/10.2.0/include
/usr/lib/gcc/x86_64-pc-msys/10.2.0/include-fixed
/usr/include
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/../include/w32api
End of search list.
GNU C17 (GCC) version 10.2.0 (x86_64-pc-msys)
compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.1.0, MPC version 1.1.0, isl version isl-0.22.1-GMP
warning: GMP header version 6.2.0 differs from library version 6.2.1.
warning: MPC header version 1.1.0 differs from library version 1.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5dc831ba8ba50cc9f8b7e3207bc4f700
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/as.exe -v -o /tmp/ccyivrKf.o /tmp/ccHxGOyu.s
GNU assembler version 2.36.1 (x86_64-pc-msys) using BFD version (GNU Binutils) 2.36.1
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-msys/10.2.0/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/:/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-msys/10.2.0/collect2.exe -plugin /usr/lib/gcc/x86_64-pc-msys/10.2.0/msys-lto_plugin.dll -plugin-opt=/usr/lib/gcc/x86_64-pc-msys/10.2.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/cc7hM2x2.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmsys-2.0 -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=msys- --tsaware -o array-indexing.exe /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/crt0.o /usr/lib/gcc/x86_64-pc-msys/10.2.0/crtbegin.o -L/usr/lib/gcc/x86_64-pc-msys/10.2.0 -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib/../lib -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/lib -L/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../.. /tmp/ccyivrKf.o -lgcc_s -lgcc -lmsys-2.0 -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/default-manifest.o /usr/lib/gcc/x86_64-pc-msys/10.2.0/crtend.o
COLLECT_GCC_OPTIONS='-v' '-o' 'array-indexing.exe' '-mtune=generic' '-march=x86-64'
$ file array-indexing.exe
file array-indexing.exe
array-indexing.exe: PE32+ executable (console) x86-64, for MS Windows
$ ./array-indexing.exe
./array-indexing.exe
bash: ./array-indexing.exe: cannot execute binary file: Exec format error
$
I'm at a loss. To my admittedly non-expert eye, the output looks inconspicuous. In particular, the generated file is recognized as a Windows executable.
The only thing standing out are these two warnings:
warning: GMP header version 6.2.0 differs from library version 6.2.1.
warning: MPC header version 1.1.0 differs from library version 1.2.1.
Googling didn't produce much insight — there was a broken dwarf5 a year ago, but the transcript shows it's using dwarf2, and that was about it.
Any ideas?
It's probably as ssbssa said in a comment: The compiler produced dwarf5 output which the runtime could not handle. The executable ran when stripped of debug information.
The issue was compounded because for some reason even repeated pacman -Suy didn't upgrade gcc or the binutils (I hadn't checked and thought that 10.2.0 was the latest available msys gcc version). Even though that command didn't output any error messages, it didn't upgrade non-core packages. It is possible that some msys processes still lingered and prevented upgrading non-core package upgrades, even though the installation closed the mintty console I was upgrading from.
For some reason the upgrades worked when I followed the advice on this page. I issued the command pacman --needed -S bash pacman pacman-mirrors msys2-runtime, followed by pacman -Suu, and a lot of package upgrades were performed successfully, resulting in a working toolchain.

C compilers do absolutely nothing

See title: GCC does absolutely nothing. Clang returns a linker error. After a fresh install (pacman -S gcc clang) in a directory only containing program.c, whose content is int main() { return 0; }:
$ gcc program.c
(no output)
$ gcc asdfasdf
(no output even for nonexistent file)
$ gcc
gcc.exe: fatal error: no input files
compilation terminated.
$ clang program.c
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
$ clang asdfasdf
clang: error: no such file or directory: 'asdfasdf'
clang: error: no input files
$ gcc -v asdfasdf
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-11.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev5, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-boot-ldflags='-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc' 'LDFLAGS_FOR_TARGET=-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high' --enable-linker-plugin-flags='LDFLAGS=-static-libstdc++\ -static-libgcc\ -pipe\ -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high\ -Wl,--stack,12582912'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Rev5, Built by MSYS2 project)
COMPILER_PATH=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/;C:/msys64/mingw64/bin/../lib/gcc/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/;C:/msys64/mingw64/bin/../lib/gcc/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/liblto_plugin.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\msys64\tmp\ccYYqACA.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -m i386pep -Bdynamic C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/crtbegin.o -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../.. asdfasdf -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/crtend.o
$ clang -v program.c
clang version 11.0.0 (https://github.com/msys2/MSYS2-packages ca391a3660d17cdee1e94d5afd2e72a4f750cddb)
Target: x86_64-pc-windows-msys
Thread model: posix
InstalledDir: /usr/bin
"/usr/bin/clang" -cc1 -triple x86_64-pc-windows-msys -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name program.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/11.0.0 -fdebug-compilation-dir "/c/dev/opengl/\$" -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o /tmp/program-cff7ba.o -x c program.c
clang -cc1 version 11.0.0 based upon LLVM 11.0.0 default target x86_64-pc-msys
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/clang/11.0.0/include
/usr/include/w32api
/usr/include
End of search list.
"/usr/bin/x86_64-pc-msys-gcc" -v -m64 -o a.exe /tmp/program-cff7ba.o
Using built-in specs.
COLLECT_GCC=/usr/bin/x86_64-pc-msys-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/11.2.0/lto-wrapper.exe
Target: x86_64-pc-msys
Configured with: /c/S/gcc/src/gcc-11.2.0/configure --build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit --with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as --disable-isl-version-check --enable-checking=release --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-msys/11.2.0/:/usr/lib/gcc/x86_64-pc-msys/11.2.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/11.2.0/:/usr/lib/gcc/x86_64-pc-msys/:/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../x86_64-pc-msys/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-msys/11.2.0/:/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../x86_64-pc-msys/lib/../lib/:/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../x86_64-pc-msys/lib/:/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-m64' '-o' 'a.exe' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'
/usr/lib/gcc/x86_64-pc-msys/11.2.0/collect2.exe -plugin /usr/lib/gcc/x86_64-pc-msys/11.2.0/msys-lto_plugin.dll -plugin-opt=/usr/lib/gcc/x86_64-pc-msys/11.2.0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/ccDITezv.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmsys-2.0 -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id -m i386pep --wrap _Znwm --wrap _Znam --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwmRKSt9nothrow_t --wrap _ZnamRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=msys- --tsaware -o a.exe /usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../lib/crt0.o /usr/lib/gcc/x86_64-pc-msys/11.2.0/crtbegin.o -L/usr/lib/gcc/x86_64-pc-msys/11.2.0 -L/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../x86_64-pc-msys/lib/../lib -L/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../x86_64-pc-msys/lib -L/usr/lib/gcc/x86_64-pc-msys/11.2.0/../../.. /tmp/program-cff7ba.o -lgcc_s -lgcc -lmsys-2.0 -ladvapi32 -lshell32 -luser32 -lkernel32 -lgcc_s -lgcc /usr/lib/gcc/x86_64-pc-msys/11.2.0/../../../../lib/default-manifest.o /usr/lib/gcc/x86_64-pc-msys/11.2.0/crtend.o
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
$ pacman -Qi | awk '/^Name/ { print $3 }' | tr '\n' ' '
(list all installed packages)
asciidoc autoconf autoconf2.13 autogen automake-wrapper automake1.10 automake1.11 automake1.12 automake1.13 automake1.14 automake1.15 automake1.16 automake1.6 automake1.7 automake1.8 automake1.9 base bash bash-completion binutils bison brotli bsdtar btyacc bzip2 ca-certificates clang cmake coreutils curl dash db diffstat diffutils docbook-xml docbook-xsl dos2unix expat file filesystem findutils flex gawk gcc gcc-libs gdb gdbm getent gettext gettext-devel git glib2 gmp gnupg gperf grep groff gzip heimdal heimdal-libs help2man icu inetutils info intltool isl jsoncpp less libarchive libargp libasprintf libassuan libatomic_ops libbz2 libcrypt libcurl libdb libedit libexpat libffi libgc libgcrypt libgdbm libgettextpo libgnutls libgpg-error libgpgme libguile libhogweed libiconv libiconv-devel libidn2 libintl libksba libltdl liblz4 liblzma libmetalink libnettle libnghttp2 libnpth libopenssl libp11-kit libpcre libpcre16 libpcre2_16 libpcre2_32 libpcre2_8 libpcre2posix libpcre32 libpcrecpp libpcreposix libpipeline libpsl libreadline librhash libsqlite libssh2 libtasn1 libtool libunistring libunrar libunrar-devel libutil-linux libuv libxml2 libxslt libxxhash libzstd llvm m4 make man-db mingw-w64-x86_64-adwaita-icon-theme mingw-w64-x86_64-atk mingw-w64-x86_64-binutils mingw-w64-x86_64-brotli mingw-w64-x86_64-bzip2 mingw-w64-x86_64-ca-certificates mingw-w64-x86_64-cairo mingw-w64-x86_64-crt-git mingw-w64-x86_64-expat mingw-w64-x86_64-fontconfig mingw-w64-x86_64-freetype mingw-w64-x86_64-fribidi mingw-w64-x86_64-gcc mingw-w64-x86_64-gcc-ada mingw-w64-x86_64-gcc-fortran mingw-w64-x86_64-gcc-libgfortran mingw-w64-x86_64-gcc-libs mingw-w64-x86_64-gcc-objc mingw-w64-x86_64-gdb mingw-w64-x86_64-gdb-multiarch mingw-w64-x86_64-gdk-pixbuf2 mingw-w64-x86_64-gettext mingw-w64-x86_64-giflib mingw-w64-x86_64-glib2 mingw-w64-x86_64-gmp mingw-w64-x86_64-graphite2 mingw-w64-x86_64-gtk-update-icon-cache mingw-w64-x86_64-gtk3 mingw-w64-x86_64-harfbuzz mingw-w64-x86_64-headers-git mingw-w64-x86_64-hicolor-icon-theme mingw-w64-x86_64-isl mingw-w64-x86_64-jbigkit mingw-w64-x86_64-json-glib mingw-w64-x86_64-lerc mingw-w64-x86_64-libdatrie mingw-w64-x86_64-libdeflate mingw-w64-x86_64-libepoxy mingw-w64-x86_64-libffi mingw-w64-x86_64-libgccjit mingw-w64-x86_64-libiconv mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-libmangle-git mingw-w64-x86_64-libpng mingw-w64-x86_64-librsvg mingw-w64-x86_64-libsystre mingw-w64-x86_64-libtasn1 mingw-w64-x86_64-libthai mingw-w64-x86_64-libtiff mingw-w64-x86_64-libtre-git mingw-w64-x86_64-libwebp mingw-w64-x86_64-libwinpthread-git mingw-w64-x86_64-libxml2 mingw-w64-x86_64-lzo2 mingw-w64-x86_64-make mingw-w64-x86_64-mpc mingw-w64-x86_64-mpdecimal mingw-w64-x86_64-mpfr mingw-w64-x86_64-ncurses mingw-w64-x86_64-openssl mingw-w64-x86_64-p11-kit mingw-w64-x86_64-pango mingw-w64-x86_64-pcre mingw-w64-x86_64-pixman mingw-w64-x86_64-pkgconf mingw-w64-x86_64-python mingw-w64-x86_64-readline mingw-w64-x86_64-shared-mime-info mingw-w64-x86_64-sqlite3 mingw-w64-x86_64-tcl mingw-w64-x86_64-termcap mingw-w64-x86_64-tk mingw-w64-x86_64-tools-git mingw-w64-x86_64-tzdata mingw-w64-x86_64-windows-default-manifest mingw-w64-x86_64-wineditline mingw-w64-x86_64-winpthreads-git mingw-w64-x86_64-winstorecompat-git mingw-w64-x86_64-xxhash mingw-w64-x86_64-xz mingw-w64-x86_64-zlib mingw-w64-x86_64-zstd mintty mpc mpdecimal mpfr msys2-keyring msys2-launcher msys2-runtime msys2-runtime-devel msys2-w32api-headers msys2-w32api-runtime nano ncurses neofetch nettle openssh openssl p11-kit pacman pacman-contrib pacman-mirrors patch patchutils pcre pcre2 perl perl-Authen-SASL perl-Clone perl-Convert-BinHex perl-Encode-Locale perl-Error perl-File-Listing perl-HTML-Parser perl-HTML-Tagset perl-HTTP-Cookies perl-HTTP-Daemon perl-HTTP-Date perl-HTTP-Message perl-HTTP-Negotiate perl-IO-HTML perl-IO-Socket-SSL perl-IO-Stringy perl-LWP-MediaTypes perl-Locale-Gettext perl-MIME-tools perl-MailTools perl-Module-Build perl-Net-HTTP perl-Net-SMTP-SSL perl-Net-SSLeay perl-TermReadKey perl-Test-Pod perl-TimeDate perl-Try-Tiny perl-URI perl-WWW-RobotRules perl-XML-Parser perl-YAML-Syck perl-inc-latest perl-libwww pinentry pkgconf pkgfile python quilt rebase reflex scons sed swig tar tcl texinfo texinfo-tex tftp-hpa time ttyrec tzcode unrar util-linux vim wget which windows-default-manifest xmlto xxhash xz zlib zstd

GCC built out ELF64 binary but cannot execute binary file: Exec format error

I met strange issues about ELF32/ELF64 format in my building machine.
Both applications and kernle module don't work.
For applications (such as helloworld program), it can be built out to ELF64 but run failed.
For kernel modules it will always be built out to ELF32 format even if append -march=x86-64 to CFLGAS, which leads to Module has invalid ELF structures issue when insmoding.
If append -m64 and it will lead to cc1: error: CPU you selected does not support x86-64 instruction set
I guess when the first question fixed, the next will also be fixed, so I only post the first one here.
Ubunt 18.04, gcc 7.5.0 , x86_64 PC
GCC built out helloworld program to ELF64 binary but cannot run
gcc -o hello -v -c hello.c
...
chmod +x hello
./hello
-bash: ./hello: cannot execute binary file: Exec format error
uname -a
Linux AELAB146 5.4.0-74-generic #83~18.04.1-Ubuntu SMP Tue May 11 16:01:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
Kernel Module's Makefile
EXTRA_CFLAGS += -Wall (and others blablabla) -m64
KERNEL_BUILD ?= /lib/modules/$(shell uname -r)/build
pcie_objs := common/init.o common/pcie.o common/net.o platform.o
obj-m := pcie.o
pcie.o: $(pcie_objs)
ld -r $^ -o $#
all:
make -C $(KERNEL_BUILD) M=$(PWD) V=1 modules
I'v no idea about why it's so long for the gcc Configured options in my system.
You're not supposed to pass -c to GCC when building an executable. It means to compile and not link, but programs need to be linked to be ran. The fact that you had to do chmod +x hello should have been a clue that you were doing something very wrong. Run gcc -o hello -v hello.c and then ./hello.
I assume your issue with kernel modules is similarly caused by an incorrect command line, but since you didn't post the command line you used for it, I can't see where you went wrong with it.

Which libraries are used by the make process?

My build is failing to link, probably because it's attempting to link against the wrong version of libaries (namely, libssl). The makefile's LIBS directive specifies -lssl, which isn't explicit enough: I have many of these on my system (various system SDKs + newly downloaded version).
My general question is, is there a verbosity option for having make print the explicit paths of the libs used for linking?
Gil.
To see the link step in detail you would usually pass a "verbose" option to the compiler or linker. What system are you using? If gcc, add -v to the compile command. This will produce output like
$ gcc -v hello.c
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)
/usr/libexec/gcc/i386-redhat-linux/4.1.2/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=generic -auxbase hello -version -o /tmp/ccAtBXVy.s
ignoring nonexistent directory "/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i386-redhat-linux/4.1.2/include
/usr/include
End of search list.
GNU C version 4.1.2 20080704 (Red Hat 4.1.2-50) (i386-redhat-linux)
compiled by GNU C version 4.1.2 20080704 (Red Hat 4.1.2-50).
GGC heuristics: --param ggc-min-expand=81 --param ggc-min-heapsize=95810
Compiler executable checksum: d8d95095eb3c93dae4bed2137d559f95
as -V -Qy -o /tmp/ccDL1N2O.o /tmp/ccAtBXVy.s
GNU assembler version 2.17.50.0.6-14.el5 (i386-redhat-linux) using BFD version 2.17.50.0.6-14.el5 20061020
/usr/libexec/gcc/i386-redhat-linux/4.1.2/collect2 --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.. /tmp/ccDL1N2O.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/4.1.2/crtend.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o
Where the last line is the link command in all its glory. The -L options specify the directories where the libs given by -l are searched, in order.

Resources