HumbleUI / JWM

Cross-platform window management and OS integration library for Java
Apache License 2.0
546 stars 44 forks source link

Ninja fatal error LNK1112: module machine type 'x86' #264

Closed Quezion closed 1 year ago

Quezion commented 1 year ago

Opening & immediately closing this ticket to serve as search documentation for anyone else that hits the same issue while compiling JWM on Windows 10.

My issue was that Ninja defaulted to 32-bit (x86) compilation due to the parent shell being configured for x32 compilation. This is default for nearly all Visual Studio 2019 command lines, including those opened within the application. It also breaks the subsequent LINK step, which is expecting compiled 64-bit obj files.

To fix, run the build script inside of x64 Native Tools Command Prompt for VS 2019, found at C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\VC in my Windows installation. (You may need to run python script/clean.py before to clear your cached x32 files.)

The Build instructions at https://github.com/HumbleUI/JWM/blob/main/docs/windows/build.md actually do mention this -- open one of the command prompts for VS 2019 matching your arch. However, this is an easy detail for one to miss when they've been living in Clojure-land for 9 years.

Output from a bugged run in x32 shell -- note compiler selected was x86/cl.exe

PS C:\Users\Quest\repos\humbleui\JWM> python .\script\build.py
-- The CXX compiler identification is MSVC 19.29.30136.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Java home found by JAVA_HOME env variable: C:\Program Files\Java\jdk-17.0.2
-- Configuring done (1.4s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/Quest/repos/humbleui/JWM/windows/build
[22/22] Linking CXX shared library jwm_x64.dll
FAILED: jwm_x64.dll jwm_x64.lib
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=CMakeFiles\jwm.dir --rc="D:\Windows Kits\10\bin\10.0.19041.0\x86\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.19041.0\x86\mt.exe" --manifests  -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx86\x86\link.exe /nologo CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\Log.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\StringUTF16.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\Window.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\impl\Library.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\impl\Managed.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\impl\RefCounted.cc.obj CMakeFiles\jwm.dir\cc\AppWin32.cc.obj CMakeFiles\jwm.dir\cc\ClipboardWin32.cc.obj CMakeFiles\jwm.dir\cc\ContextWGL.cc.obj CMakeFiles\jwm.dir\cc\LayerD3D12.cc.obj CMakeFiles\jwm.dir\cc\LayerRaster.cc.obj CMakeFiles\jwm.dir\cc\LayerWGL.cc.obj CMakeFiles\jwm.dir\cc\ThemeWin32.cc.obj CMakeFiles\jwm.dir\cc\ScreenWin32.cc.obj CMakeFiles\jwm.dir\cc\WindowManagerWin32.cc.obj CMakeFiles\jwm.dir\cc\WindowWin32.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12CommandQueue.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12Common.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12Device.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12Fence.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12SwapChain.cc.obj  /out:jwm_x64.dll /implib:jwm_x64.lib /pdb:jwm_x64.pdb /dll /version:0.0 /machine:X86 /INCREMENTAL:NO  /INCREMENTAL:NO /NODEFAULTLIB:MSVCRT /machine:X64  shcore.lib  gdi32.lib  opengl32.lib  user32.lib  Dxva2.lib  d3d12.lib  dxgi.lib  dxguid.lib  Imm32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
LINK: command "C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx86\x86\link.exe /nologo CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\Log.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\StringUTF16.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\Window.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\impl\Library.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\impl\Managed.cc.obj CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\impl\RefCounted.cc.obj CMakeFiles\jwm.dir\cc\AppWin32.cc.obj CMakeFiles\jwm.dir\cc\ClipboardWin32.cc.obj CMakeFiles\jwm.dir\cc\ContextWGL.cc.obj CMakeFiles\jwm.dir\cc\LayerD3D12.cc.obj CMakeFiles\jwm.dir\cc\LayerRaster.cc.obj CMakeFiles\jwm.dir\cc\LayerWGL.cc.obj CMakeFiles\jwm.dir\cc\ThemeWin32.cc.obj CMakeFiles\jwm.dir\cc\ScreenWin32.cc.obj CMakeFiles\jwm.dir\cc\WindowManagerWin32.cc.obj CMakeFiles\jwm.dir\cc\WindowWin32.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12CommandQueue.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12Common.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12Device.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12Fence.cc.obj CMakeFiles\jwm.dir\cc\D3D12\DX12SwapChain.cc.obj /out:jwm_x64.dll /implib:jwm_x64.lib /pdb:jwm_x64.pdb /dll /version:0.0 /machine:X86 /INCREMENTAL:NO /INCREMENTAL:NO /NODEFAULTLIB:MSVCRT /machine:X64 shcore.lib gdi32.lib opengl32.lib user32.lib Dxva2.lib d3d12.lib dxgi.lib dxguid.lib Imm32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:jwm_x64.dll.manifest" failed (exit code 1112) with the following output:
CMakeFiles\jwm.dir\C_\Users\Quest\repos\humbleui\JWM\shared\cc\Log.cc.obj : fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64'
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "C:\Users\Quest\repos\humbleui\JWM\script\build.py", line 46, in <module>
    sys.exit(main())
  File "C:\Users\Quest\repos\humbleui\JWM\script\build.py", line 40, in main
    res += build_native()
  File "C:\Users\Quest\repos\humbleui\JWM\script\build.py", line 12, in build_native
    subprocess.check_call(["ninja"], cwd = "build")
  File "C:\Python310\lib\subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja']' returned non-zero exit status 1.

Beginning of output from a successful run -- note x64/cl.exe

C:\Users\Quest\repos\humbleui\JWM>python script/build.py
-- The CXX compiler identification is MSVC 19.29.30136.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped

Hope this saves someone a few minutes; maybe future me? 😉

tonsky commented 1 year ago

Thanks! Setting up Windows build is such a pain