aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
978 stars 625 forks source link

how to cross compiling on my arm platform #1796

Closed linsijia1002 closed 2 years ago

linsijia1002 commented 2 years ago

hi : So far I have compiled successfully on ubuntu18.04, and then I want to compile on the arm Linux platform. How should I configure it? My cross-compilation tool is shown in the following image: image

Please help me solve it, the sooner the better, thank you very much!!

jasonpcarroll commented 2 years ago

Hi @linsijia1002, Sorry for the late reply. Since this repo utilizes the CMAKE build tool - refer to https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html to cross-compile. Best, Jason

archigup commented 2 years ago

In order to cross-compile for another platform using CMake, you will need a sysroot and a cmake toolchain file.

You could obtain a sysroot by setting up an arm linux system with the required dependencies and copying its root filesystem for use as your sysroot. Then can follow the prior linked documentation to write a toolchain file.

archigup commented 2 years ago

For example here is a sample toolchain file for compiling for an armv7 target:

SET(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "armv7")
set(CMAKE_SYSROOT "/path/to/target/rootfs/")

set(CROSS_TARGET "arm-linux-gnueabihf")

set(CMAKE_C_COMPILER "${CROSS_TARGET}-gcc")
set(CMAKE_CXX_COMPILER "${CROSS_TARGET}-g++")

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)

update the sysroot to where you have copied the root filesystem of the target.