赞
踩
因工作需要移植微软的物联网SDK,通过文档交叉编译出了sdk库,在此记录下编译方法.
1. 先下载 SDK (azure-iot-sdk-c: https://github.com/Azure/azure-iot-sdk-c/tree/2018-09-11),有一点要提示下,我在下载SDK时最开始选择的是 DownLoad ZIP,这样下载下来的SDK不完整有很多依赖的文件夹内容都下载不下来,后面安装了git工具才拿到完整的代码(git clone -b <yyyy-mm-dd> --recursive https://github.com/Azure/azure-iot-sdk-c.git) https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/devbox_setup.md#linux
2. 编译前的准备,交叉编译azure-iot-sdk-c需要用到 curl库和openssl库和uuid库,在网上下载源码交叉编译好,由于这几个库我做项目经常用到所以我统一放在一个公共目录里面方便使用
3. 需要的库准备好后就要根据文档来进行编译了。这里面用的是cmake,我电脑上装的有现成的,没有的自行安装,运行cmake指令前,需要添加一些配置,指定用什么编译器,库的目录等等,创建一个配置文件 toolchain-rpi.cmake 内容如下
- 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 $ENV{RPI_ROOT}/../bin/arm-linux-gnueabihf-gcc)
- SET(CMAKE_C_COMPILER /opt/hisi-linux/x86-arm/arm-hisiv600-linux/target/bin/arm-hisiv600-linux-gcc)
-
-
- # this is the file system root of the target
- #SET(CMAKE_FIND_ROOT_PATH $ENV{RPI_ROOT})
- SET(CMAKE_FIND_ROOT_PATH /test/azure-iot-sdk-c/DEMO)
-
- # 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)
参考文档: https://github.com/Azure/azure-iot-sdk-c/blob/2018-09-11/doc/SDK_cross_compile_example.md
放入
最后在当前目前下执行 指令 ./build.sh --toolchain-file toolchain-rpi.cmake --provisioning -cl -L/test/azure-iot-sdk-c/DEMO/lib
最终结果:
生成的库在
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。