1

在使用 CMake 交叉编译适用于 C 的 Azure IoT SDK 时,它还尝试构建一些示例。但它不会将这些样本与 libcurl 链接起来,即-lcurl相应的命令行中缺少这些样本。因此,我得到了很多未定义的引用。例如:

../../../c-utility/libaziotsharedutil.a(httpapi_curl.c.o): In function `HTTPAPI_Init':
httpapi_curl.c:(.text+0x408): undefined reference to `curl_global_init'

这就是我调用构建脚本的方式:

cd azure-iot-sdk-c/build_all/linux && ./build.sh --toolchain-file ../../../_toolchain.cmake -cl --sysroot=$(ROOTFS_STAGING_PATH)

这就是我的工具链文件的样子:

INCLUDE(CMakeForceCompiler)

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)

SET(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PATH}/bin/$ENV{LNXP_TARGET}-gcc)
SET(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PATH}/bin/$ENV{LNXP_TARGET}-g++)

SET(CMAKE_SYSROOT $ENV{ROOTFS_STAGING_PATH})
SET(CMAKE_FIND_ROOT_PATH $ENV{ROOTFS_STAGING_PATH})

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(CURL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/include)
SET(CURL_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/lib)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/include)
LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../Supplies/curl/lib)

SET(use_default_uuid ON CACHE BOOL "")

SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "")

我滥用工具链文件来设置一些选项,因为构建脚本不允许我直接设置选项。

这是构建示例的命令行的样子:

/<toolchain path>/arm-sc1x5-linux-gnueabihf-gcc --sysroot=/<sysroot path> --sysroot=/<sysroot path> -fPIC  -Werror  -rdynamic CMakeFiles/iothub_convenience_sample.dir/iothub_convenience_sample.c.o CMakeFiles/iothub_convenience_sample.dir/__/__/__/certs/certs.c.o  -o iothub_convenience_sample  -L/<curl path>/lib -Wl,-rpath,/<curl path>/lib:/usr/local/lib ../../libiothub_client.a ../../libiothub_client_http_transport.a ../../libiothub_client_amqp_transport.a ../../libiothub_client_amqp_ws_transport.a ../../../uamqp/libuamqp.a ../../../c-utility/libaziotsharedutil.a ../../libiothub_client_mqtt_transport.a ../../libiothub_client_mqtt_ws_transport.a ../../../umqtt/libumqtt.a ../../../libparson.a ../../../c-utility/libaziotsharedutil.a /<sysroot path>/usr/local/lib/libssl.so /<sysroot path>/usr/local/lib/libcrypto.so -lpthread -lm -lrt

我到底在用什么药?

4

0 回答 0