xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

x86 build does not produce valid Win32 (XP) application #5287

Closed ArgoreOfficial closed 4 months ago

ArgoreOfficial commented 4 months ago

Xmake Version

2.9.3

Operating System Version and Architecture

Windows 10, XP Pro

Describe Bug

building a basic "Hello World" program using -a x86 does not create a valid 32-bit application
runs fine on my x64 machine, but will not launch in a Windows XP Pro virtual machine

I have tried both MSVC and clang, neither create a valid application

Expected Behavior

targetting x86/32bit should create a valid 32-bit application

Project Configuration

xmake.lua

target( "test" )
    set_kind( "binary" )
    add_files( "./main.cpp" )

main.cpp

#include <stdio.h>

int main()
{
    printf("Hello World XP\n");

    while(true){} // so the console doesn't disappear

    return 0;
}

build command xmake f -p windows -a x86 xmake

Additional Information and Error Logs

checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x86\cl.exe
checking for the c++ compiler (cxx) ... cl.exe
[ 50%]: compiling.release main.cpp
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x86\\cl.exe" -c -nologo /EHsc -Fobuild\.objs\test\windows\x86\release\main.cpp.obj main.cpp
checking for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x86\cl.exe ... ok
checking for flags (cl_sourceDependencies) ... ok
> cl.exe "/sourceDependencies" "C:\Users\argore\AppData\Local\Temp\.xmake\240701\_2D1B1657C7084E008FCEAD95777D8D80.json" "-nologo"
[ 75%]: linking.release test.exe
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x86\\link.exe" -nologo -dynamicbase -nxcompat -machine:x86 -out:build\windows\x86\release\test.exe build\.objs\test\windows\x86\release\main.cpp.obj
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x86\cl.exe
checking for the c compiler (cc) ... cl.exe

build cache stats:
cache directory: build\.build_cache
cache hit rate: 0%
cache hit: 0
cache hit total time: 0.000s
cache miss: 0
cache miss total time: 0.000s
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0.000s

[100%]: build ok, spent 0.375s
star-hengxing commented 4 months ago

https://learn.microsoft.com/en-us/cpp/build/configuring-programs-for-windows-xp?view=msvc-170

TL,DR: Windows XP programs require <= MSVC V141 toolset.

Other ways:

add_requires("yy-thunks")
add_packages("yy-thunks")

add_rules("@yy-thunks/xp")
ArgoreOfficial commented 4 months ago

ohh I see
compiling using the i86-w64-mingw32 toolchain manually worked

is there a way to select which MSVC toolset version to use?

star-hengxing commented 4 months ago
$ xmake f --vs_toolset=<version>

or

set_toolchains("msvc", {vs_toolset = ""})
ArgoreOfficial commented 4 months ago

ended up going with mingw