Cross-compiling for ARM64 using Visual Studio and WSL2 is generating x64 binary

15 hours ago 1
ARTICLE AD BOX

I was using VS2026, but have switched back to VS2022 for now. The project is a MSBuild project, not a CMake project. I have the C++ ARM64/ARM64EC build tools installed (latest) and I have all the required libraries and tools installed in WSL. However, for some reason it keeps building Advanced Micro Devices X86-64 binaries.

My .vcxproj has only 2 configurations, ARM and ARM64, and ARM64 is set config manager.

When I set the build output to Diagnostic, I can see that it is setting the Platform as ARM64 (sample provided below) and it even outputs the binary to the ARM64 output directory, yet nothing I do will force it to build an ARM64 binary.

1>------ Rebuild All started: Project: NativeSerialPort, Configuration: ReleaseLinux ARM64 ------ 1> Using "Message" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". 1> Task "Message" 1> Task Parameter:Importance=Low 1> Task Parameter:Text=Configuration=ReleaseLinux 1> Configuration=ReleaseLinux 1> Done executing task "Message". 1> Task "Message" 1> Task Parameter:Importance=Low 1> Task Parameter:Text=Platform=ARM64 1> Platform=ARM64

When I inspect the library with file (on WSL), this is says X64 and the library, and as expected, the library fails to load under arm64 install.

libNativeSerialPort.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=96996de8ea441261e335bc02b46910918d61eaa9, with debug_info, not stripped

Looking further at the output from the build I can see the options that VS is telling gcc to use, but I cannot find any reference to the tool it is actually using to do the build.

Compiling sources: 1> g++ -c -x c++ /root/projects/NativeSerialPort/NativeSerialPort.cpp -g1 -o "/root/projects/NativeSerialPort/obj/ARM64/ReleaseLinux/NativeSerialPort.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O3 -fno-strict-aliasing -fomit-frame-pointer -D_DEFAULT_SOURCE -DNDEBUG -fpic -fthreadsafe-statics -fexceptions -frtti -std=c++11 1> NativeSerialPort.cpp

Is there anywhere I am missing when you need to specify what toolchain to use? The only option I can see in Visual Studio is WSL2 GCC Toolset.

I have no idea what I am doing wrong here.

Read Entire Article