Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
587 stars 739 forks source link

Cannot find -lparson #2487

Closed zambranohally closed 1 year ago

zambranohally commented 1 year ago

I have a cross platform project that will use iothub in c++. I am using Visual Studio 2022 together cmake and vcpkg. install the latest release for vcpkg. Below are my steps in installing the azure-iot-sdk-c.

- ./vcpkg install azure-iot-sdk-c:x64-linux

- After the installation I updated the cmakelists.txt and add the following
find_package(azure_iot_sdks CONFIG REQUIRED)
target_link_libraries(vianad PRIVATE iothub_client serializer prov_auth_client hsm_security_client)

- Below is the screenshot of the cmake generation.
![image](https://github.com/Azure/azure-iot-sdk-c/assets/63218980/9d2046be-5c8d-42bd-b6d0-3a48835011d3)

- When I build the code, I got this error
![image](https://github.com/Azure/azure-iot-sdk-c/assets/63218980/05d3906d-ee1a-4d66-8f21-c4641531938a)
ericwolz commented 1 year ago

You need to install the parson vcpkg package.

C:\Repos\vcpkg>vcpkg search parson
parson                   2022-11-13       a lightweight json library written in C
zambranohally commented 1 year ago

@ericwol-msft Thank you for your reply. I did install parson and also added it to cmakelists.txt but still the error persist.

ericwolz commented 1 year ago

dump your linker paths and see what is going on.

zambranohally commented 1 year ago

@ericwol-msft I am using cmake all of my other libraries are working except azure iot.

ericwolz commented 1 year ago

You can use cmake options--debug-output and --trace to debug your cmake.

zambranohally commented 1 year ago

@ericwol-msft This is what I got. image

ericwolz commented 1 year ago

This is a paho mqqt issues and not related to this repo. Have you tried searching the internet for your issue?

https://www.google.com/search?q=paho-mqtt+websocket.c+%22undefined+reference+to+uuid_generate%22&rlz=1C1RXQR_enUS1031US1031&sxsrf=APwXEdeApn8L3CkZ0lYCFT2SUBKl3JfEgQ%3A1685471876790&ei=hEJ2ZKDRL4a80PEP0qOF4A8&ved=0ahUKEwigo_qD2J3_AhUGHjQIHdJRAfwQ4dUDCBA&uact=5&oq=paho-mqtt+websocket.c+%22undefined+reference+to+uuid_generate%22&gs_lcp=Cgxnd3Mtd2l6LXNlcnAQAzIFCAAQogQyBQgAEKIEMgUIABCiBDIFCAAQogQyBQgAEKIEOgoIABBHENYEELADOgcIIRCgARAKOgcIIRCrAhAKOgUIIRCrAkoECEEYAFDWBVityAFgjckBaAFwAXgAgAF3iAHCBZIBAzguMZgBAKABAcABAcgBCA&sclient=gws-wiz-serp

zambranohally commented 1 year ago

@ericwol-msft sorry for my previous post but that was already solve. I mistakenly paste the wrong screenshot. Please can you help me what is wrong, what am I lacking. I already added parson in cmakelists still the error persist.

root@xxx:/mnt/e/c++/xxx# cmake --build /root/.vs/xxx/out/build/linux-debug --target xxx--config Debug --verbose [1/1] : && /usr/bin/g++ -g CMakeFiles/xxx.dir/sources/xxx.cpp.o CMakeFiles/xxx.dir/sources/db_config.cpp.o CMakeFiles/xxx.dir/sources/api.cpp.o CMakeFiles/xxx.dir/sources/options.cpp.o CMakeFiles/xxx.dir/sources/cli.cpp.o CMakeFiles/xxx.dir/sources/m_device.cpp.o CMakeFiles/xxx.dir/sources/heartbeat.cpp.o CMakeFiles/xxx.dir/sources/m_heartbeat.cpp.o CMakeFiles/xxx.dir/sources/device.cpp.o CMakeFiles/xxx.dir/sources/camera.cpp.o CMakeFiles/xxx.dir/sources/m_camera.cpp.o CMakeFiles/xxx.dir/sources/m_rss_payload.cpp.o CMakeFiles/xxx.dir/sources/mqtt.cpp.o CMakeFiles/xxx.dir/sources/mqtt_callback.cpp.o CMakeFiles/xxx.dir/sources/command_queue.cpp.o CMakeFiles/xxx.dir/sources/command_consumer.cpp.o -o xxx /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libserializer.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libprov_auth_client.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libhsm_security_client.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libboost_program_options.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libspdlogd.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libpaho-mqttpp3.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libpaho-mqtt3as.a -luuid /mnt/e/vcpkg/installed/x64-linux/debug/lib/libuhttp.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_http_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_amqp_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_amqp_ws_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libuamqp.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libssl.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libcrypto.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_mqtt_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_mqtt_ws_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libumqtt.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libaziotsharedutil.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libcurl-d.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libz.a -lm -lparson /mnt/e/vcpkg/installed/x64-linux/debug/lib/libfmtd.a -lstdc++ /mnt/e/vcpkg/installed/x64-linux/debug/lib/libpaho-mqtt3cs.a -lc /mnt/e/vcpkg/installed/x64-linux/debug/lib/libssl.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libcrypto.a -lpthread -ldl -lpthread -lrt -lanl && : FAILED: xxx : && /usr/bin/g++ -g CMakeFiles/xxx.dir/sources/vianad.cpp.o CMakeFiles/xxx.dir/sources/db_config.cpp.o CMakeFiles/xxx.dir/sources/api.cpp.o CMakeFiles/vianad.dir/sources/options.cpp.o CMakeFiles/vianad.dir/sources/cli.cpp.o CMakeFiles/xxx.dir/sources/m_device.cpp.o CMakeFiles/xxx.dir/sources/heartbeat.cpp.o CMakeFiles/xxx.dir/sources/m_heartbeat.cpp.o CMakeFiles/xxx.dir/sources/device.cpp.o CMakeFiles/xxx.dir/sources/camera.cpp.o CMakeFiles/xxx.dir/sources/m_camera.cpp.o CMakeFiles/xxx.dir/sources/m_rss_payload.cpp.o CMakeFiles/xxx.dir/sources/mqtt.cpp.o CMakeFiles/xxx.dir/sources/mqtt_callback.cpp.o CMakeFiles/xxx.dir/sources/command_queue.cpp.o CMakeFiles/xxx.dir/sources/command_consumer.cpp.o -o xxx /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libserializer.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libprov_auth_client.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libhsm_security_client.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libboost_program_options.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libspdlogd.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libpaho-mqttpp3.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libpaho-mqtt3as.a -luuid /mnt/e/vcpkg/installed/x64-linux/debug/lib/libuhttp.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_http_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_amqp_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_amqp_ws_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libuamqp.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libssl.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libcrypto.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_mqtt_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libiothub_client_mqtt_ws_transport.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libumqtt.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libaziotsharedutil.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libcurl-d.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libz.a -lm -lparson /mnt/e/vcpkg/installed/x64-linux/debug/lib/libfmtd.a -lstdc++ /mnt/e/vcpkg/installed/x64-linux/debug/lib/libpaho-mqtt3cs.a -lc /mnt/e/vcpkg/installed/x64-linux/debug/lib/libssl.a /mnt/e/vcpkg/installed/x64-linux/debug/lib/libcrypto.a -lpthread -ldl -lpthread -lrt -lanl && : /usr/bin/ld: cannot find -lparson collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.

ericwolz commented 1 year ago

are you using the cmake option use_installed_dependencies

if(${use_installed_dependencies})
    find_package(parson REQUIRED CONFIG)
endif()

You need to a.) dump the cmake generate debug and find out how parson is getting pulled in. b.) dump the linker paths and find out why the lib can not be found.

CIPop commented 1 year ago

@RLeclair, @vaavva and I looked at this today. The issue is that cmake does not detect the path: -lparson instead of something on the lines of /mnt/e/vcpkg/installed/x64-linux/debug/lib/libparson.a.

We couldn't find anything that changed in our library. My suspicion is that https://github.com/microsoft/vcpkg/pull/27885 might have changed something that we need to update on our side.

dg0yt commented 1 year ago

We couldn't find anything that changed in our library. My suspicion is that microsoft/vcpkg#27885 might have changed something that we need to update on our side.

What microsoft/vcpkg#27885 changed is that instead of creating parson as an alias target for vcpkg's proprietary unofficial::parson::parson, it now relies on parson's official cmake config which provides an imported target parson::parson.

So in vcpkg, azure-iot-sdk-c's use of target_link_libraries(... parson) is no longer backed by a target with location properties. And due to absence of a namespace::, CMake can't offer good diagnostics but must pass parson as namespec to the linker (-lparson). Which may or may not find some matching lib, and not necessarily at the location provided by find_package(parson CONFIG REQUIRED).

So the bug is here, indeed, and you need to update how the projects links to parson in CMake, in this and other spots: https://github.com/Azure/azure-iot-sdk-c/blob/97fef570416467598100b782ef27ceadad9ca796/serializer/CMakeLists.txt#L71 should either become

target_link_libraries(serializer parson::parson) 

or an alias needs to be created again. (This is the new fix in vcpkg.) (And maybe it would be good to start using the PUBLIC/PRIVATE/INTERFACE keywords, but this has a larger scope.)

CIPop commented 1 year ago

Thank you @dg0yt for your detailed answer and the fix in VCPKG!

In the future, we plan to add VCPKG support within the library itself (instead of maintaining .patch files in VCPKG) as well as a CI step that uses VCPKG (to detect issues faster instead of just during our release workflow).

@zambranohally this issue should be fixed within LTS_08_2023