module machine type 'x86' conflicts with target machine type 'x64'
HerrNamenlos123 opened this issue · 14 comments
I just created a very simple project using Chalet and wanted to build it, but I am hit with this error.
I downloaded the currently latest version of Chalet.
I am on Windows 11, using VS2022.
I simply ran chalet init
and hit enter until it finishes. I did not change anything.
Then, I ran chalet build
and I am hit with this error.
chalet.json:
{
"name": "chalet-test",
"version": "1.0.0",
"targets": {
"chalet-test": {
"kind": "executable",
"language": "C++",
"settings:Cxx": {
"cppStandard": "c++20",
"warningsPreset": "pedantic",
"precompiledHeader": "src/pch.hpp",
"includeDirs": [
"src"
]
},
"files": "src/**.cpp"
}
},
"distribution": {
"all": {
"kind": "bundle",
"buildTargets": "*"
}
}
}
.chaletrc:
{
"options": {
"dumpAssembly": false,
"showCommands": false,
"benchmark": true,
"launchProfiler": true,
"keepGoing": false,
"generateCompileCommands": true,
"onlyRequired": false,
"maxJobs": 16,
"toolchain": "vs-stable",
"configuration": "Release",
"architecture": "auto",
"inputFile": "chalet.json",
"envFile": ".env",
"rootDir": "",
"outputDir": "build",
"externalDir": "chalet_external",
"distributionDir": "dist",
"osTargetName": "",
"osTargetVersion": "",
"signingIdentity": "",
"lastTarget": "all",
"runArguments": {}
},
"toolchains": {
"vs-stable": {
"x86_64": {
"version": "17.7.34221.43",
"strategy": "native",
"buildPathStyle": "target-triple",
"compilerCpp": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/cl.exe",
"compilerC": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/cl.exe",
"compilerWindowsResource": "C:/Program Files (x86)/Windows Kits/10/bin/10.0.22621.0/x64/rc.exe",
"linker": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/link.exe",
"archiver": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/lib.exe",
"profiler": "C:/Program Files/Microsoft Visual Studio/2022/Community/Team Tools/Performance Tools/x64/vsinstr.exe",
"disassembler": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/dumpbin.exe",
"cmake": "C:/Program Files/CMake/bin/cmake.exe",
"make": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/nmake.exe",
"ninja": "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe"
}
}
},
"tools": {
"bash": "C:/Users/zachs/AppData/Local/Microsoft/WindowsApps/bash.exe",
"command_prompt": "C:/Windows/System32/cmd.exe",
"git": "C:/Program Files/Git/bin/git.exe",
"ldd": "C:/Program Files/Git/usr/bin/ldd.exe",
"powershell": "C:/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe"
}
}
Terminal:
>>> chalet build
> Reading Build File [chalet.json] ... done (14ms)
> Reading Microsoft® Visual C/C++ Environment Cache ... done
> Configuring build ... done (1ms)
> Resolving source file dependencies ... done (1ms)
> C++ Compiler: Microsoft® Visual C/C++ version 19.37.32825 (VS 17.7.34221.43)
> Target Architecture: x86_64-pc-windows-msvc
> Strategy: Native
> Configuration: Release
▼ Build: chalet-test.exe
[1/1] Linking build/x86_64-pc-windows-msvc_Release/chalet-test.exe
FAILED: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/link.exe /nologo /incremental:NO /libpath:build/x86_64-pc-windows-msvc_Release dbghelp.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /subsystem:console /opt:REF /opt:ICF /dynamicbase /nxcompat /machine:X64 /entry:mainCRTStartup /out:build/x86_64-pc-windows-msvc_Release/chalet-test.exe build/x86_64-pc-windows-msvc_Release/obj.chalet-test/src/main.cpp.obj build/x86_64-pc-windows-msvc_Release/obj.chalet-test/chalet-test_manifest.rc.res build/x86_64-pc-windows-msvc_Release/obj.chalet-test/src/pch.hpp.obj
build\x86_64-pc-windows-msvc_Release\obj.chalet-test\src\main.cpp.obj : fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64'
✘ Failed!
Review the errors above.
So the reason for the error is because the Hostx86/x86
paths was detected with x86_64
but I'm not sure why. I've never seen that before.
Do you have the x64 host build tools installed, or only the x86 host version?
Edit: I think I found the bug. It was an old oversight (because I never tested vs presets w/o x64 host tools)
Try this version: 0.7.4
It should be fixed. You'll want to remove build
and .chaletrc
in the project directory before building again.
Thank you for taking a look at it!
I have now downloaded the latest 0.7.5. I have deleted build and .chaletrc. Unfortunately now I get this error:
chalet configure
> Creating Microsoft® Visual C/C++ Environment Cache ... done (3.067s)
ERROR: Architecture 'x86_64-pc-windows-msvc' is not supported by the 'vs-stable' toolchain.
ERROR: Unexpected compiler toolchain structure found from executable: 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/cl.exe'
Both toolchains seem to be installed, but chalet should be able to handle it
Odd, does it work if you use either of these?
chalet -t vs-stable -a x86 build
(Should resolve to .../Hostx86/x86/...
)
chalet -t vs-stable -a x86_x64 build
(Should resolve to .../Hostx86/x64/...
)
For the record, my Windows machine is also on Windows 11 with the exact same MSVC version otherwise. Any strange background about your MSVC/VS installation? Your machine is definitely x64 right, not x86 or arm64?
Edit: To clarify, the error is technically correct, because you're running the x64 version of chalet, the default target architecture is x64 (aka when you pass -a auto
). Because it's still resolving to .../Hostx86/x86/..
, that tells me you either only have that version of the compiler installed or maybe also have the .../Hostx86/x64/...
one. Admittedly, not the most helpful error message.
Could you also confirm that your C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\lib
path has an x64
and x86
folder?
... and that C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include
exist?
... and just for completeness, that C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin
has Hostx64/x64
, Hostx64/x86
and Hostx86/x64
?
So:
Clean project and chalet build
:
> Reading Build File [chalet.json] ... done (32ms)
> Creating Microsoft (R) Visual C/C++ Environment Cache ... done (1.612s)
ERROR: Architecture 'x86_64-pc-windows-msvc' is not supported by the 'vs-stable' toolchain.
ERROR: Unexpected compiler toolchain structure found from executable: 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/cl.exe'
Clean project and chalet -t vs-stable -a x86 build
:
> Reading Build File [chalet.json] ... done (29ms)
> Creating Microsoft (R) Visual C/C++ Environment Cache ... done (1.825s)
> Configuring build ... done (2ms)
> Resolving source file dependencies ... done (4ms)
> C++ Compiler: Microsoft (R) Visual C/C++ version 19.37.32825 (VS 17.7.34221.43)
> Target Architecture: i686-pc-windows-msvc
> Strategy: Native
> Configuration: Release
» Build: chalet-test.exe
[1/4] src/pch.hpp
[2/4] src/main.cpp
[3/4] build/i686-pc-windows-msvc_Release/int/chalet-test_manifest.rc
[4/4] Linking build/i686-pc-windows-msvc_Release/chalet-test.exe
Target is up to date.
Time: 1.466s
√ Succeeded!
Total: 1.472s
Clean project and chalet -t vs-stable -a x86_x64 build
> Reading Build File [chalet.json] ... done (28ms)
> Creating Microsoft (R) Visual C/C++ Environment Cache ... done (1.971s)
ERROR: Architecture 'x86_64-pc-windows-msvc' is not supported by the 'vs-stable' toolchain.
ERROR: Unexpected compiler toolchain structure found from executable: 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx86/x86/cl.exe'
It almost seems like x64 is not even installed but it must be, I am constantly building x64 projects. I am not building x86. My machine is definitely x64, a new Lenovo Yoga with i7 12th Gen CPU. I only resetted it recently and MSVC is a normal community edition install. Really nothing special.
My VS Installer says, that
- Windows 11 SDK
- MSVC v143 - VS 2022 C++ x64/x86 build tools
- C++ ATL for latest v143 build tools (x86 and x64)
and many more are installed. I don't think it is even possible to install only x64 or only x86 and not both.
Let me check my folders:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\lib
has x64
AND x86
folders.
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include
does exist.
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin
has Hostx64
and Hostx86
, both of which have x64
and x86
folders each.
So for example, C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\cl.exe
also exists.
Thanks for confirming -- those are all good. The only other thing this could possibly be is that the wrong architecture is being called with vcvarsall.bat
for some reason.
Run these two sets of commands from separate terminals:
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
where cl
Expected: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx64\x64\cl.exe
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
where cl
Expected: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\Hostx86\x86\cl.exe
If those are both expected, remove build
and .chaletrc
again and run this version of chalet:
At the top, you should see this:
> Reading Build File [chalet.json] ... done (6ms)
-- target architecture from input: x86_64
-- target architecture x64
-- before call to vcvarsall.bat: x64 x64
> Creating Microsoft® Visual C/C++ Environment Cache ... "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
But I think in your case, it's resulting in x86. Send me what you see there instead.
Oh, I think we are getting somewhere. If I call the first pair of commands, both x86 and x64 cl.exe are found. I confirmed that x86 cl is already found in a fresh terminal, and after calling vcvarsall, both x86 and x64 are found with which cl
. I now remember why: I once had to use x86 objdump for something and i simply added the x86 folder to the PATH variable, so i can call objdump from everywhere. It was by far the easiest solution for me. Sorry about that, that was the only non-standard thing with my installation.
Now, before simply removing it from PATH, is there a way to handle this? I have not had any issue until now and all other C++ build systems still work flawlessly. I am sure there are quite a few people that do this sort of thing and might then have issues with Chalet. I remember having the same error like a year ago when first trying Chalet, and then giving up on it because not even a hello world worked. Now I gave it another try.
So thank you for finding the culprit but do you think you can handle this case in Chalet to be more robust?
Ah! Confirmed I can recreate the issue now on my machine.
I'll do some digging. I have to remember how Path
is getting constructed - When vcvarsall gets called, a delta of the environment is created in the cache, but when that gets read back in, the existing Path vars might be placed in front of the VS ones.
Edit: Another complication is .env
files. If you had one with this:
Path=C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/HostX86/x86;%Path%
My expectation is that the x64 build should fail, because it's user error - you'd be overriding the Path in the local project directory because the x86 path is before %Path%
. Would you agree?
Actually, this is a moot point because the .env is read before vcvarsall is called. I'll figure something out.
I don't think having either PATH or a .env file set should cause a build to fail, no user error to me. I am not sure how CMake or Chalet do it but in my mind absolute paths are always used. The compiler isn't in Path anyways and it also shouldn't be after calling a build step. I would think a toolchain is found at the beginning by checking SDK install locations, and cached as an absolute path to an executable. When building, only the absolute path is executed. So in my mind there would not be a single command lookup that is not absolute and thus PATH shouldn't have any effect.
Not informed about how systems do it but that would be my interpretation.
Yeah I think CMake just honors what vcvarsall sets. The next Chalet version (which should be out in a haft hour or so) will to the same. There was an old code path that was trying to be smart about where the VS paths gets inserted in the Path variable. The only real reason why I was doing that was so a user could prefer another cmake.exe, or ninja.exe instead of the ones included with VS, but it's probably not necessary. They could always change the toolchain after it's generated.
Try this out:
Appreciate the help in tracking this one down. Let me know if you run into any other issues.
Yep, I can confirm that the hello world project now builds out of the box with chalet build
and I did not change any settings on my machine. Thank you very much for the effort! For me this issue can be closed now.
Sounds good! If you have any general questions or need help with anything, feel free to make use of the discussions board:
https://github.com/chalet-org/chalet/discussions
I'm generally looking for feedback about clarity of documentation, anything that doesn't work as you would expect, and obviously any features you'd like to see. I appreciate you trying out the app!