How to cross compile with cmake + arm-none-eabi on windows? How to cross compile with cmake + arm-none-eabi on windows? windows windows

How to cross compile with cmake + arm-none-eabi on windows?


Turning my comment into an answer

I've given a reduced version of your an example a try. I could reproduce your initial error and could fix the compiler detection by setting CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY. But then building an "executable" would still fail.

So you can set CMAKE_EXE_LINKER_FLAGS_INIT to --specs=nosys.specs (since those are linker flags). Just make sure to start from an empty binary output directory if you are using ..._INIT flags, since the resulting CMAKE_EXE_LINKER_FLAGS is cached.

I prefer to force the result CMAKE_EXE_LINKER_FLAGS variable (INTERNAL does imply FORCE).

CMakeLists.txt

cmake_minimum_required(VERSION 3.6)project(testApp)file(WRITE main.cpp "int main(void) { return 0; }")set(testApp "testApp")list(    APPEND testApp_sources        main.cpp)add_executable(    ${testApp}    ${testApp_sources})

toolchain.cmake

set(CMAKE_SYSTEM_NAME Generic)set(CMAKE_SYSTEM_PROCESSOR arm)set(CMAKE_C_COMPILER "arm-none-eabi-gcc.exe")set(CMAKE_CXX_COMPILER "arm-none-eabi-g++.exe")set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "")set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

Does:

build> cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE:PATH="..\toolchain.cmake"  ..-- The C compiler identification is GNU 6.3.1-- The CXX compiler identification is GNU 6.3.1-- Check for working C compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-gcc.exe-- Check for working C compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-gcc.exe -- works-- Detecting C compiler ABI info-- Detecting C compiler ABI info - done-- Detecting C compile features-- Detecting C compile features - done-- Check for working CXX compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-g++.exe-- Check for working CXX compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-g++.exe -- works-- Detecting CXX compiler ABI info-- Detecting CXX compiler ABI info - done-- Detecting CXX compile features-- Detecting CXX compile features - done-- Configuring done-- Generating done-- Build files have been written to: buildbuild> cmake --build .Scanning dependencies of target testApp[ 50%] Building CXX object CMakeFiles/testApp.dir/main.obj[100%] Linking CXX executable testApp[100%] Built target testApp

References