Use a Linux CMake inside of WSL2 when targeting Linux compilations, not a Windows one. CMake binaries are platform-specific (that is, CMake is not a “cross-compiler” so to speak). This is also seen where CMake for Windows, CMake for MinGW, and CMake for Cygwin are three different things. Yes, they all run on “Windows”, but they use and target different runtimes. It’s all the same codebase, but the compilation target changes behaviors that are important to the platform at hand.