c++visual-studio-codecmakemingwsdl-3

Encountering PCH allocation failure when compile with mingw64+cmake(Ninja)+sdl3


Question:

  1. In which case the "PCH allocation failure" is going happened even the main memory is enough.
  2. What is the address in "MapViewOfFileEx: Attempt to access invalid address.". It's the address of hard drive or main memory.

Pre requirements:

  1. CMake: https://cmake.org/download/

  2. Compile toochain: w64devkit v2.3.0 (x86_64-w64-mingw32-gcc 15.1.0) https://github.com/skeeto/w64devkit/releases/tag/v2.3.0 sha256:7afcd52a57dc5fdb2ebc524f0645f3dda7f67cd287f836b0cee1fe855d76a81e

  3. Ninja generator: https://github.com/ninja-build/ninja/releases ninja-win.zip sha256:26a40fa8595694dec2fad4911e62d29e10525d2133c9a4230b66397774ae25bf

  4. libsdl3 (Source code): https://github.com/libsdl-org/SDL/releases/tag/release-3.2.18 source-code

  5. VSCode with CMake and C/CPP extensions installed.

Main actions:

  1. Create directories:
./
./Src/main.cpp
./Inc/main.hpp
./Lib
./Lib/SDL3 (Extrated from libsdl3 source code)
./CMakeLists.txt
  1. Edit CMakeLists.txt
cmake_minimum_required(VERSION 3.20)

project(test CXX)

add_subdirectory(./Lib/SDL3)
add_executable(test ./Src/main.cpp)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

target_compile_features(test PUBLIC cxx_std_17)
target_link_libraries(test PUBLIC SDL3::SDL3)
  1. Edit main.cpp
#include <iostream>
#include <SDL3/SDL.h>
using namespace std;
int main(){
    cout << "words" << endl;
    return 0;
}

Operations in VSCode:

  1. Open CMake settings.
  2. Fill "Ninja" in "default generator"
  3. Ensure "path to CMake" is available for Extension to access
  4. Close setting and swich to main.cpp
  5. Swich to side pannel CMake Extension
  6. Finding "_Unspecified" , click "Pen" figure.
  7. Select the path to where w64devkit has extracted. (VSCode could discovered GCC/G++ 15.0.1)
  8. Ctrl + Shift + P, select "cmake:configure" showing configurations done.
  9. Ctrl + Shift + P, select "cmake:debug" cmake is going to compile the project automatically. Then suspended with PCH failure during compilation process, randomly.
  10. If compilation runs normally, copying ./build/SDL3/SDL3.dllto ./build (same directory where test.exe is)

Notice:

  1. Copies can be compiled and on another system with Windows 11 installed.

  2. Copies can be compiled and run on Ubuntu VM of problem system.

  3. Other CMake project with only standard libraries can be debug on problem system.

  4. Tried different build of MinGW64, the same error occurred.

  5. Tried makefile setting by CMake, the same error occurred.

  6. Msys2 can't be installed properly on problem system.

  7. Tried lower the threads of ninja by using "Ninja -j4" ,"Ninja -j1" in terminal after 8. , but the same error.

Here is failure outputs from terminal. Key information located in the end of content.

[build] [77/270  27% :: 4.638] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_mouse.c.obj
[build] FAILED: Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_mouse.c.obj
[build] e:\Software\w64devkit\w64devkit\bin\gcc.exe -DDLL_EXPORT -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=18 -DSDL_BUILD_MINOR_VERSION=2 -DUSING_GENERATED_CONFIG_H -IE:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/include-config-debug/build_config -IE:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/include-revision -IE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/include -IE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src -g -gdwarf-4 -Wall -Wundef -Wfloat-conversion -fno-strict-aliasing -Wshadow -Wno-unused-local-typedefs -Wimplicit-fallthrough -fdiagnostics-color=always -idirafterE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src/video/khronos -Winvalid-pch -include E:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/cmake_pch.h -MD -MT Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_mouse.c.obj -MF Lib\SDL-release-3.2.18\CMakeFiles\SDL3-shared.dir\src\events\SDL_mouse.c.obj.d -o Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_mouse.c.obj -c E:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src/events/SDL_mouse.c
[build] internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.cc:186: MapViewOfFileEx: Attempt to access invalid address.
[build] <command-line>: sorry, unimplemented: PCH allocation failure
[build] [77/270  28% :: 4.983] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_quit.c.obj
[build] FAILED: Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_quit.c.obj
[build] e:\Software\w64devkit\w64devkit\bin\gcc.exe -DDLL_EXPORT -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=18 -DSDL_BUILD_MINOR_VERSION=2 -DUSING_GENERATED_CONFIG_H -IE:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/include-config-debug/build_config -IE:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/include-revision -IE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/include -IE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src -g -gdwarf-4 -Wall -Wundef -Wfloat-conversion -fno-strict-aliasing -Wshadow -Wno-unused-local-typedefs -Wimplicit-fallthrough -fdiagnostics-color=always -idirafterE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src/video/khronos -Winvalid-pch -include E:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/cmake_pch.h -MD -MT Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_quit.c.obj -MF Lib\SDL-release-3.2.18\CMakeFiles\SDL3-shared.dir\src\events\SDL_quit.c.obj.d -o Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_quit.c.obj -c E:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src/events/SDL_quit.c
[build] internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.cc:186: MapViewOfFileEx: Attempt to access invalid address.
[build] <command-line>: sorry, unimplemented: PCH allocation failure
[build] [77/270  28% :: 5.108] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_scancode_tables.c.obj
[build] FAILED: Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_scancode_tables.c.obj
[build] e:\Software\w64devkit\w64devkit\bin\gcc.exe -DDLL_EXPORT -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=18 -DSDL_BUILD_MINOR_VERSION=2 -DUSING_GENERATED_CONFIG_H -IE:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/include-config-debug/build_config -IE:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/include-revision -IE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/include -IE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src -g -gdwarf-4 -Wall -Wundef -Wfloat-conversion -fno-strict-aliasing -Wshadow -Wno-unused-local-typedefs -Wimplicit-fallthrough -fdiagnostics-color=always -idirafterE:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src/video/khronos -Winvalid-pch -include E:/Programs/GitHub/IDLE_Miacis/build/Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/cmake_pch.h -MD -MT Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_scancode_tables.c.obj -MF Lib\SDL-release-3.2.18\CMakeFiles\SDL3-shared.dir\src\events\SDL_scancode_tables.c.obj.d -o Lib/SDL-release-3.2.18/CMakeFiles/SDL3-shared.dir/src/events/SDL_scancode_tables.c.obj -c E:/Programs/GitHub/IDLE_Miacis/Lib/SDL-release-3.2.18/src/events/SDL_scancode_tables.c
[build] internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.cc:186: MapViewOfFileEx: Attempt to access invalid address.
[build] <command-line>: sorry, unimplemented: PCH allocation failure
[build] ninja: build stopped: subcommand failed.
[proc] The command: CMake --build e:/Programs/GitHub/IDLE_Miacis/build --config Debug --target all -- exited with code: 1
[driver] Build completed: 00:00:05.161
[build] Build finished with exit code 1
[main] Failed to prepare executable target with name "undefined"
mkdir build
cd build
cmake .. -G Ninja 
cmake --build ./ --config Debug --target all --

But same action runs properly on another system.

Here is successful outputs from terminal on another PC.

[main] The folder containing the CMake cache is missing. The cache will be regenerated.
[main] Configuring project: IDLE_SDL_Linker
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=d:\Software\w64devkit\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=d:\Software\w64devkit\bin\g++.exe --no-warn-unused-cli -S D:/Programs/IDLE_SDL_Linker -B d:/Programs/IDLE_SDL_Linker/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 15.1.0
[cmake] -- The CXX compiler identification is GNU 15.1.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: d:/Software/w64devkit/bin/gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: d:/Software/w64devkit/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found PkgConfig: D:/Software/w64devkit/bin/pkg-config.exe (found version "0.34.0")
[cmake] -- Detecting Target CPU Architecture
[cmake] -- Detecting Target CPU Architecture - X64
[cmake] -- Performing Test HAVE_GDWARF_4
[cmake] -- Performing Test HAVE_GDWARF_4 - Success...
[cmake] -- Looking for shellscalingapi.h - found
[cmake] -- Performing Test HAVE_MFAPI_H
[cmake] -- Performing Test HAVE_MFAPI_H - Success
[cmake] -- Checking for module 'libusb-1.0>=1.0.16'
[cmake] --   pkg-config: could not find package 'libusb-1.0'
[cmake] -- Could NOT find LibUSB (missing: LibUSB_LIBRARY LibUSB_INCLUDE_PATH) (found version "LibUSB_VERSION-NOTFOUND")
[cmake] -- 
[cmake] -- SDL3 was configured with the following options:
[cmake] -- 
[cmake] -- Platform: Windows-10.0.26100
[cmake] -- 64-bit:   TRUE
[cmake] -- Compiler: d:/Software/w64devkit/bin/gcc.exe
[cmake] -- Revision: SDL3-3.2.18-GIT-NOTFOUND
[cmake] -- Vendor:   
[cmake] -- 
[cmake] -- Subsystems:
[cmake] --   Audio:    ON...
[build] [268/270  96% :: 52.220] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3_test.dir/src/test/SDL_test_crc32.c.obj
[build] [268/270  97% :: 52.221] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3_test.dir/src/test/SDL_test_font.c.obj
[build] [268/270  97% :: 52.221] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3_test.dir/src/test/SDL_test_fuzzer.c.obj
[build] [268/270  97% :: 52.356] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3_test.dir/src/test/SDL_test_harness.c.obj
[build] [268/270  98% :: 52.438] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3_test.dir/src/test/SDL_test_log.c.obj
[build] [268/270  98% :: 52.525] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3_test.dir/src/test/SDL_test_md5.c.obj
[build] [268/270  98% :: 53.184] Linking C shared library Lib\SDL-release-3.2.18\SDL3.dll
[build] [269/270  99% :: 53.737] Building C object Lib/SDL-release-3.2.18/CMakeFiles/SDL3_test.dir/src/test/SDL_test_memory.c.obj
[build] [270/270  99% :: 53.789] Linking CXX executable sdl_fw.exe
[build] [270/270 100% :: 54.143] Linking C static library Lib\SDL-release-3.2.18\libSDL3_test.a
[driver] Build completed: 00:00:54.430
[build] Build finished with exit code 0
[proc] Executing command: d:/Software/w64devkit/bin/gdb.exe --version

Solution

  • The reason of this error happened, is that ASLR has ENABLED (one of antivirus action of Windows protection).

    The most direct way to solve this problem is by disabling all ASLR action in Windows Security.

    This action leads to PCH allocation failure. More details could be found here :

    The explanation in details

    Similar topics has already been discussed on Stack Overflow:

    Answer can also be found in this topics

    In addiction, I've also noticed that this action is also leads to the installation of msys2 and the running of git.

    (The installation of msys2 is probably using git bash so that the same error occurred.) The details could be found here:

    enter image description here

    Suggested "could not fork child process"