cross compile azure iot sdk

2019-08-14 16:24发布

问题:

I try to crosscompile the Azure IoT C SDK (https://github.com/azure/azure-iot-sdk-c) for a BeagleBoard Black.

I did setup a Debian GNU/Linux 8.7 (jessie) Machine and installed the toolchain as described here: http://exploringbeaglebone.com/chapter7/.

Then i followed the steps here: https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/SDK_cross_compile_example.md and Created a Toolchain file:

INCLUDE(CMakeForceCompiler)

SET(CMAKE_SYSTEM_NAME Linux)     # this one is important
SET(CMAKE_SYSTEM_VERSION 1)     # this one not so much

# this is the location of the amd64 toolchain targeting the Raspberry Pi
SET(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_FIND_ROOT_PATH /usr/lib/arm-linux-gnueabihf)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

i call the Buildscript of the azure-sdk using:

./build.sh --toolchain-file toolchain-bb.cmake -cl --sysroot=/usr/lib/arm-linux-gnueabihf

The following Error Occures

CMake Error at /usr/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES
  OPENSSL_INCLUDE_DIR)
    Call Stack (most recent call first):
    /usr/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:343 (_FPHSA_FAILURE_MESSAGE)
    /usr/share/cmake-3.0/Modules/FindOpenSSL.cmake:328 (find_package_handle_standard_args)
  c-utility/CMakeLists.txt:141 (find_package)

i tried to install openssl using:

sudo apt-get install openssl:armhf 

but the error remains, if i build the source for arm64 (using just the build.sh file of the azure-iot-sdk) everything works fine.

if i clone openssl and build it targeting arm i get the following error:

CMake Error at /usr/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES) (found
  version "1.1.1")

回答1:

If you have Openssl present in your tool chain then you simply need to add a couple of additional lines to your cmake toolchain file. This will help cmake find your libraries and headers. Something like this:

SET(OPENSSL_ROOT_DIR /path/to/openssl/lib) SET(OPENSSL_INCLUDE_DIR /path/to/openssl/include/)

If it is not present then you will need to cross compile openssl for your target and install it into your toolchain. Typically into /<sysroot>/usr/lib and /<sysroot>/usr/include.

Alternatively if openssl is on your device but not in your toolchain then you can simply copy it from the device. There is an example of copying dependencies to the toolchain in the Raspberry Pi demo here: https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/SDK_cross_compile_example.md