Skip to content

Instantly share code, notes, and snippets.

@BCadet
Created June 15, 2022 16:05
Show Gist options
  • Save BCadet/14702ff403e249de721e0fd3ccf7bb18 to your computer and use it in GitHub Desktop.
Save BCadet/14702ff403e249de721e0fd3ccf7bb18 to your computer and use it in GitHub Desktop.
cross-compilation with CMake tutorial on Windows

Cross-compile on Windows with CMake

Prerequire

  • PC on Windows 10
  • Basic understanding of CMake

Install of MSYS2

MSYS2 is a collection of tools and libraries providing you with an easy-to-use environment for building, installing and running native Windows software.

To install it, follow the instructions provided in the link above.

CMake specific packages installation

After the installation procedure of MSYS2, install CMake and make with the folowing command:

pacman -S cmake make

cross toolchain installation

I highly recommand to manually download a toolchain from the official website of the toolchain (example: https://developer.arm.com/downloads/-/gnu-rm for GNU arm-none- toolchain) You will need to provide the toolchain path to CMake through sepcifics variables:

  • CMAKE_C_COMPILER
  • CMAKE_CXX_COMPILER
  • CMAKE_ASM_COMPILER
  • CMAKE_OBJCOPY
  • CMAKE_OBJDUMP
  • CMAKE_SIZE
  • CMAKE_DEBUGER
  • CMAKE_CPPFILT

All theses variables can be specified in a separate file passed to CMake with the variable CMAKE_TOOLCHAIN_FILE.

folder navigation

In MSYS2, you can access the Windows file stystem inside the folder /c/

build

Inside a MSYS2 console, you can simple call cmake and make as you would do on linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment