Open
Description
Hello,
I'm using the msgpack-c library in my project. I've been working with the msgpack_pack_str_body
and msgpack_pack_int16
functions without problem. Now I want to use the msgpack_unpack_next
and msgpack_object_print
functions as in the "Simple program with a loop" but I get the following compilation error:
[5/7] Linking CXX executable mqtt_tcp.elf
FAILED: mqtt_tcp.elf
.
.
.
b/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: esp-idf/main/libmain.a(message_pack_functions.c.obj): in function `messagepack_encoding':
/home/esp/IoTlift/mqtt-tcp/build/../main/message_pack_functions.c:77: undefined reference to `msgpack_unpack_next'
/home/.espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: /home/esp/IoTlift/mqtt-tcp/build/../main/message_pack_functions.c:81: undefined reference to `msgpack_object_print'
/home/.espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld: esp-idf/main/libmain.a(message_pack_functions.c.obj): in function `msgpack_unpacked_destroy':
/home/esp/IoTlift/mqtt-tcp/build/../msgpack-c/msgpack-c-c_master/include/msgpack/unpack.h:260: undefined reference to `msgpack_zone_free'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
Nevertheless, the library is included in the project and msgpack_zone_free
is in "zone.h" file which is included in "unpack.h" file. How can I solve this problem?
Activity
redboltz commentedon Aug 24, 2022
msgpack_pack_str_body is an inline function.
msgpack-c/cmake/pack_template.h.in
Lines 782 to 785 in c3df1bb
msgpack_zone_free is not an inline function.
msgpack-c/src/zone.c
Lines 217 to 222 in c3df1bb
So you need to link the library
libmsgpackc.a
.marco711 commentedon Aug 24, 2022
Thank you. How do I link this library?
redboltz commentedon Aug 24, 2022
See your compiler/linker manual. Usualy
-lmsgpackc
.marco711 commentedon Aug 25, 2022
Hello,
I'm using ESP-IDF which uses CMake and Ninja build. I've been reviewing the *cmake and CMakeLists.txt files in order to try to link the library
libmsgpackc.a
but it is not clear for me how to do the linking.redboltz commentedon Aug 25, 2022
Here are example source files and CMakeLists.txt.
The following line might help you.
https://github.com/msgpack/msgpack-c/blob/c_master/example/CMakeLists.txt#L22
You can also try https://github.com/msgpack/msgpack-c/tree/c_master#install-from-git-repository instruction.
marco711 commentedon Aug 25, 2022
Thank you. I have tried to reinstall the library with the []((https://github.com/msgpack/msgpack-c/tree/c_master#install-from-git-repository) instruction and the linking still fails. Then, I've tried by modifying the CMakeLists.txt file in the msgpack-c folder but I still get the linking error at the same line. Finally, I've tried by modifying the CMakeLists.txt file in the folder containing the "app_main.c" file and I the linker cannot find the "nvs_flash.h" file.
redboltz commentedon Aug 25, 2022
It seems that the issue is caused by your code not msgpack-c. I cant help you any more.
marco711 commentedon Aug 25, 2022
OK, thanks for your time. I will recreate the project from scratch.
marco711 commentedon Aug 26, 2022
Hello,
I have downloaded the MQTT-TCP example and I have downloaded and installed the msgpack-c library in the folder "tcp". Then, I have included the library (
#include <msgpack.h>
) and added some of its functions in the main function:The build fails with the same error (
undefined reference to ...
). Did I install the msgpack library in the wrong folder? Moreover, it is not clear for me how to modify the CMakeLists.txt files. Any help will be appreciated.vk015 commentedon Apr 25, 2023
I have also build the project and tried to run the example programs, but getting the undefined reference error while linking..