首页 > 解决方案 > Azure iot sdk c 示例:CMakeLists.txt 有效,但 make (Autotools) 无效

问题描述

我有以下问题,不知道如何解决。

我在自己的项目中使用 iothub_ll_client_x509_sample (azure iot sdk c)。如果我使用 CMakeLists.txt 编译项目一切正常。但是如果我使用 Makefile.am (Autotools) 来编译程序,我会得到几个未定义的引用。

CMakeLists.txt 看起来像这样

cmake_minimum_required(VERSION 2.8.11)

set(AZUREIOT_INC_FOLDER ".." "/usr/local/include/azureiot" "/usr/local/include/azure_c_shared_utility" "/usr/local/include/azure_prov_client")

include_directories(${AZUREIOT_INC_FOLDER})

add_executable(sample_app azureSendingMessageMain.cc)

target_link_libraries(sample_app
    iothub_client_mqtt_transport
    iothub_client_amqp_transport
    iothub_client_http_transport
    iothub_client
    umqtt
    prov_auth_client
    hsm_security_client
    uhttp
    aziotsharedutil
    parson
    uuid
    pthread
    curl
    ssl
    crypto
    m
)

我的 Makefile.am 看起来像这样

bin_PROGRAMS = azureSendingMessage

azureSendingMessage_SOURCES = azureSendingMessageMain.cc 

azureSendingMessage_CPPFLAGS = -isystem/usr/local/include/azureiot 

azureSendingMessage_LDADD = /usr/local/lib/libiothub_client_mqtt_transport.a \
                    /usr/local/lib/libiothub_client_amqp_transport.a \
                    /usr/local/lib/libiothub_client_http_transport.a \
                    /usr/local/lib/libiothub_client.a \
                    /usr/local/lib/libumqtt.a \
                    /usr/local/lib/libprov_auth_client.a \
                    /usr/local/lib/libhsm_security_client.a \
                    /usr/local/lib/libuhttp.a \
                    /usr/local/lib/libaziotsharedutil.a \
                    /usr/local/lib/libparson.a \
                    -luuid \
                    -lpthread \
                    -lcurl \
                    -lssl \
                    -lcrypto \
                    -lm

所以两者都有完全相同的链接库顺序。

如果我尝试使用 Makefile 编译程序,我会收到以下错误

/bin/bash ../libtool  --tag=CXX   --mode=link g++ -Wall -Werror -Wformat-security -Wignored-qualifiers -Wlogical-op -Wmissing-include-dirs -Wpointer-arith -Wundef -Wduplicated-cond -Wshift-negative-value -Wshift-overflow=2 -Wfloat-conversion -Wsized-deallocation -Wlogical-not-parentheses -Wno-strict-aliasing -g -O2 -pipe -fno-implement-inlines  -O3   -o iotProcess iotProcess-iotProcess.o iotProcess-TMPMsgIot.o iotProcess-IotCloudComm.o iotProcess-MessageHandler.o iotProcess-jsonUtil.o /usr/local/lib/libiothub_client_mqtt_transport.a /usr/local/lib/libiothub_client_amqp_transport.a /usr/local/lib/libiothub_client_http_transport.a /usr/local/lib/libiothub_client.a /usr/local/lib/libumqtt.a /usr/local/lib/libprov_auth_client.a /usr/local/lib/libhsm_security_client.a /usr/local/lib/libuhttp.a /usr/local/lib/libaziotsharedutil.a ../common/libbpng.la ../configuration/libconfiguration.la ../common/tmpMsg/libtmpmsg.la ../common/util/libutil.la /opt/telemotive/lib/i686-linux-gnu/libtmtrace.la /opt/telemotive/lib/i686-linux-gnu/libtmutil.la /opt/telemotive/lib/i686-linux-gnu/libtmproc.la /opt/telemotive/lib/i686-linux-gnu/libtmio.la /opt/telemotive/lib/i686-linux-gnu/libtmpbus.la -lpthread -lcurl -lssl -lcrypto -lm -lxerces-c -luuid /usr/local/lib/libparson.a -lmscan_api -lmdis_api
libtool: link: g++ -Wall -Werror -Wformat-security -Wignored-qualifiers -Wlogical-op -Wmissing-include-dirs -Wpointer-arith -Wundef -Wduplicated-cond -Wshift-negative-value -Wshift-overflow=2 -Wfloat-conversion -Wsized-deallocation -Wlogical-not-parentheses -Wno-strict-aliasing -g -O2 -pipe -fno-implement-inlines -O3 -o .libs/iotProcess iotProcess-iotProcess.o iotProcess-TMPMsgIot.o iotProcess-IotCloudComm.o iotProcess-MessageHandler.o iotProcess-jsonUtil.o  /usr/local/lib/libiothub_client_mqtt_transport.a /usr/local/lib/libiothub_client_amqp_transport.a /usr/local/lib/libiothub_client_http_transport.a /usr/local/lib/libiothub_client.a /usr/local/lib/libumqtt.a /usr/local/lib/libprov_auth_client.a /usr/local/lib/libhsm_security_client.a /usr/local/lib/libuhttp.a /usr/local/lib/libaziotsharedutil.a ../common/.libs/libbpng.so ../configuration/.libs/libconfiguration.so ../common/tmpMsg/.libs/libtmpmsg.so ../common/util/.libs/libutil.so /opt/telemotive/lib/i686-linux-gnu/libtmtrace.so /opt/telemotive/lib/i686-linux-gnu/libtmutil.so /opt/telemotive/lib/i686-linux-gnu/libtmproc.so /opt/telemotive/lib/i686-linux-gnu/libtmio.so /opt/telemotive/lib/i686-linux-gnu/libtmpbus.so -lpthread /usr/lib/i386-linux-gnu/libcurl-gnutls.so -lssl -lcrypto -lm -lxerces-c -luuid /usr/local/lib/libparson.a -lmscan_api -lmdis_api -pthread
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `generate_root_ca_info':
hsm_client_riot.c:(.text+0xa6): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0xc4): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0xe6): undefined reference to `X509GetDeviceCertTBS'
hsm_client_riot.c:(.text+0x150): undefined reference to `RiotCrypt_Sign'
hsm_client_riot.c:(.text+0x1b4): undefined reference to `X509MakeRootCert'
hsm_client_riot.c:(.text+0x239): undefined reference to `DERtoPEM'
hsm_client_riot.c:(.text+0x2e5): undefined reference to `X509GetDEREcc'
hsm_client_riot.c:(.text+0x34d): undefined reference to `DERtoPEM'
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `produce_device_cert':
hsm_client_riot.c:(.text+0x409): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0x426): undefined reference to `X509GetDeviceCertTBS'
hsm_client_riot.c:(.text+0x48e): undefined reference to `RiotCrypt_Sign'
hsm_client_riot.c:(.text+0x4f3): undefined reference to `X509MakeDeviceCert'
hsm_client_riot.c:(.text+0x56e): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0x58b): undefined reference to `X509GetDERCsrTbs'
hsm_client_riot.c:(.text+0x5f3): undefined reference to `RiotCrypt_Sign'
hsm_client_riot.c:(.text+0x658): undefined reference to `X509GetDERCsr'
hsm_client_riot.c:(.text+0x6c9): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0x6e6): undefined reference to `X509GetDeviceCertTBS'
hsm_client_riot.c:(.text+0x74e): undefined reference to `RiotCrypt_Sign'
hsm_client_riot.c:(.text+0x7b0): undefined reference to `X509MakeDeviceCert'
hsm_client_riot.c:(.text+0x832): undefined reference to `DERtoPEM'
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `produce_alias_key_cert':
hsm_client_riot.c:(.text+0x8c6): undefined reference to `DERtoPEM'
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `produce_alias_key_pair':
hsm_client_riot.c:(.text+0x976): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0x9d9): undefined reference to `X509GetDEREcc'
hsm_client_riot.c:(.text+0xa4e): undefined reference to `DERtoPEM'
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `produce_device_id_public':
hsm_client_riot.c:(.text+0xb01): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0xb25): undefined reference to `X509GetDEREccPub'
hsm_client_riot.c:(.text+0xb9a): undefined reference to `DERtoPEM'
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `process_riot_key_info':
hsm_client_riot.c:(.text+0xcc8): undefined reference to `RiotCrypt_Hash'
hsm_client_riot.c:(.text+0xd3f): undefined reference to `RiotCrypt_DeriveEccKey'
hsm_client_riot.c:(.text+0xdb4): undefined reference to `RiotCrypt_Hash2'
hsm_client_riot.c:(.text+0xe31): undefined reference to `RiotCrypt_DeriveEccKey'
hsm_client_riot.c:(.text+0xf84): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0xfb1): undefined reference to `X509GetAliasCertTBS'
hsm_client_riot.c:(.text+0x101c): undefined reference to `RiotCrypt_Sign'
hsm_client_riot.c:(.text+0x1084): undefined reference to `X509MakeAliasCert'
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `hsm_client_x509_init':
hsm_client_riot.c:(.text+0x1295): undefined reference to `DiceSHA256'
hsm_client_riot.c:(.text+0x12b9): undefined reference to `DiceSHA256_2'
/usr/local/lib/libhsm_security_client.a(hsm_client_riot.c.o): In function `hsm_client_riot_create_leaf_cert':
hsm_client_riot.c:(.text+0x1c22): undefined reference to `DERInitContext'
hsm_client_riot.c:(.text+0x1c3f): undefined reference to `X509GetDeviceCertTBS'
hsm_client_riot.c:(.text+0x1cad): undefined reference to `RiotCrypt_Sign'
hsm_client_riot.c:(.text+0x1d15): undefined reference to `X509MakeDeviceCert'
hsm_client_riot.c:(.text+0x1de9): undefined reference to `DERtoPEM'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `GetEkTemplate':
hsm_client_tpm.c:(.text+0x1f): undefined reference to `ToTpmaObject'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `GetSrkTemplate':
hsm_client_tpm.c:(.text+0x95): undefined reference to `ToTpmaObject'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `dps_umarshal_array':
hsm_client_tpm.c:(.text+0x114): undefined reference to `UINT32_Unmarshal'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `unmarshal_array':
hsm_client_tpm.c:(.text+0x1f2): undefined reference to `UINT32_Unmarshal'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `marshal_array_values':
hsm_client_tpm.c:(.text+0x32b): undefined reference to `UINT32_Unmarshal'
hsm_client_tpm.c:(.text+0x452): undefined reference to `UINT32_Unmarshal'
hsm_client_tpm.c:(.text+0x579): undefined reference to `UINT32_Unmarshal'
hsm_client_tpm.c:(.text+0x6a2): undefined reference to `TPM2B_PUBLIC_Unmarshal'
hsm_client_tpm.c:(.text+0x742): undefined reference to `UINT16_Unmarshal'
hsm_client_tpm.c:(.text+0x7de): undefined reference to `TPM2B_PRIVATE_Unmarshal'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `create_tpm_session':
hsm_client_tpm.c:(.text+0x8a1): undefined reference to `TSS_StartAuthSession'
hsm_client_tpm.c:(.text+0x907): undefined reference to `TSS_PolicySecret'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `insert_key_in_tpm':
hsm_client_tpm.c:(.text+0xa94): undefined reference to `TPM2B_ID_OBJECT_Unmarshal'
hsm_client_tpm.c:(.text+0xaf4): undefined reference to `TPM2B_ENCRYPTED_SECRET_Unmarshal'
hsm_client_tpm.c:(.text+0xb54): undefined reference to `TPM2B_PRIVATE_Unmarshal'
hsm_client_tpm.c:(.text+0xbb4): undefined reference to `TPM2B_ENCRYPTED_SECRET_Unmarshal'
hsm_client_tpm.c:(.text+0xc13): undefined reference to `TPM2B_PUBLIC_Unmarshal'
hsm_client_tpm.c:(.text+0xc73): undefined reference to `UINT16_Unmarshal'
hsm_client_tpm.c:(.text+0xcee): undefined reference to `TPM2_ActivateCredential'
hsm_client_tpm.c:(.text+0xd7b): undefined reference to `TPM2_Import'
hsm_client_tpm.c:(.text+0xe2d): undefined reference to `ToTpmaObject'
hsm_client_tpm.c:(.text+0xecc): undefined reference to `TSS_Create'
hsm_client_tpm.c:(.text+0xf46): undefined reference to `TPM2_Load'
hsm_client_tpm.c:(.text+0xfb4): undefined reference to `TPM2_EvictControl'
hsm_client_tpm.c:(.text+0xfdc): undefined reference to `TPM2_EvictControl'
hsm_client_tpm.c:(.text+0x1036): undefined reference to `TPM2_FlushContext'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `decrypt_data':
hsm_client_tpm.c:(.text+0x1131): undefined reference to `TSS_GetTpmProperty'
hsm_client_tpm.c:(.text+0x11f8): undefined reference to `TPM2B_ID_OBJECT_Unmarshal'
hsm_client_tpm.c:(.text+0x1258): undefined reference to `TPM2B_ENCRYPTED_SECRET_Unmarshal'
hsm_client_tpm.c:(.text+0x12b8): undefined reference to `TPM2B_PRIVATE_Unmarshal'
hsm_client_tpm.c:(.text+0x1318): undefined reference to `TPM2B_ENCRYPTED_SECRET_Unmarshal'
hsm_client_tpm.c:(.text+0x1377): undefined reference to `TPM2B_PUBLIC_Unmarshal'
hsm_client_tpm.c:(.text+0x13d7): undefined reference to `UINT16_Unmarshal'
hsm_client_tpm.c:(.text+0x14fa): undefined reference to `TPM2_ActivateCredential'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `initialize_tpm_device':
hsm_client_tpm.c:(.text+0x15dc): undefined reference to `TSS_CreatePwAuthSession'
hsm_client_tpm.c:(.text+0x1632): undefined reference to `Initialize_TPM_Codec'
hsm_client_tpm.c:(.text+0x16a9): undefined reference to `TSS_CreatePersistentKey'
hsm_client_tpm.c:(.text+0x1720): undefined reference to `TSS_CreatePersistentKey'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `hsm_client_tpm_destroy':
hsm_client_tpm.c:(.text+0x1885): undefined reference to `Deinit_TPM_Codec'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `hsm_client_tpm_get_endorsement_key':
hsm_client_tpm.c:(.text+0x1a8f): undefined reference to `TPM2B_PUBLIC_Marshal'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `hsm_client_tpm_get_storage_key':
hsm_client_tpm.c:(.text+0x1c63): undefined reference to `TPM2B_PUBLIC_Marshal'
/usr/local/lib/libhsm_security_client.a(hsm_client_tpm.c.o): In function `hsm_client_tpm_sign_data':
hsm_client_tpm.c:(.text+0x1e01): undefined reference to `SignData'
collect2: error: ld returned 1 exit status
Makefile:570: recipe for target 'iotProcess' failed
make: *** [iotProcess] Error 1

我真的不知道为什么程序不是用 make (Autotools) 而是用 CMakeLists.txt 编译的。

问题是需要使用 make 和 autotools 所以使用 CMakeLists.txt 是没有选择的:(

希望任何人都可以帮助我弄清楚make(autotools)和Makefile.am出了什么问题

编辑:

好的,我玩了很长时间并找出了问题,但没有解决方案。

正如我所说,我将 azure iot sdk 用于 c。如果我尝试使用 MQTT_Protocol,我会收到未定义的引用错误。

线条

IOTHUB_DEVICE_CLIENT_LL_HANDLE device_ll_handle;
device_ll_handle = IoTHubClientCore_LL_CreateFromConnectionString(connectionString, MQTT_Protocol);

产生错误。我对所有现有组合中的库重新排序,但仍然得到这个未定义的引用......

谁能帮我?我是否想念一些使用 MQTT_Protocol 的库?我仍然包括 libiothub_client_mqtt_transport.a、libuamqp.a 和 libumqtt.a

标签: azuremakefilecmakeautomakeazure-iot-sdk

解决方案


推荐阅读