Skip to content

Cross compiling using Visual Studio Build Tools and cmake

Notifications You must be signed in to change notification settings

JeffMill/xcompile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Visual Studio / VCPKG Build - ARM

Compilation and cross-compilation.

Download Visual Studio Build Tools

Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile "$env:TEMP/vs_BuildTools.exe"

Install Visual Studio Build Tools

When installing onto an ARM device, this will include ARM64 build tools as well as x86 and x64 1. Note that you'll need to explicitly specify ARM64 build tools ("Microsoft.VisualStudio.Component.VC.Tools.ARM64" 2) to enable cross-compilation targeting ARM64 AND to build natively on ARM64.

& "$env:TEMP/vs_BuildTools.exe" --passive --wait --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --add Microsoft.VisualStudio.Component.VC.Tools.ARM64

Add CMake to PATH

Visual Studio Build Tools includes cmake, but it's not put into the PATH.

$env:PATH += ";${Env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"

Install VCPKG

Install to \vcpkg for convenience.

git clone https://github.com/Microsoft/vcpkg.git /vcpkg

\vcpkg\bootstrap-vcpkg.bat

Build natively (x64 on x64, ARM on arm)

cmake.exe -B build -S . -D CMAKE_TOOLCHAIN_FILE='/vcpkg/scripts/buildsystems/vcpkg.cmake'

cmake.exe --build build --parallel --config Debug

build\Debug\helloworld.exe

Cross compile for ARM (on x64 device)

Important: VCPKG manifest mode doesn't work if build path includes a backslash. So don't use something like -B build\ARM64!

Specify platform name using -A ARM64. Could also use CMAKE_GENERATOR_PLATFORM or CMAKE_VS_PLATFORM_NAME

cmake.exe -B build_ARM64 -S . -D CMAKE_TOOLCHAIN_FILE='/vcpkg/scripts/buildsystems/vcpkg.cmake' -A ARM64

cmake.exe --build build_ARM64 --parallel --config Debug

Check EXE with dumpbin

Add dumpbin to PATH

On ARM device:

$dumpbin = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\bin\Hostarm64\x64\dumpbin.exe"

On x64 device:

$dumpbin = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\bin\Hostx64\x64\dumpbin.exe"

Check "machine" type

& $dumpbin /HEADERS build_ARM64\Debug\helloworld.exe | Select-String 'machine' -SimpleMatch

References

cmake - Cross compiling for x64_arm with MSVC tools on Windows - Stack Overflow

Cross Compiling With CMake — Mastering CMake

Cross-compiling under Visual Studio (#18225) · Issues · CMake - CMake · GitLab

Footnotes

  1. See Visual Studio on Arm-powered devices

  2. See the Component Directory

About

Cross compiling using Visual Studio Build Tools and cmake

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published