goToMain / libosdp

Implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol); provides a C library with support for C++, Rust and Python3
https://libosdp.sidcha.dev
Apache License 2.0
128 stars 69 forks source link

Undefined reference if linking against static library #169

Closed rherrmannr closed 4 months ago

rherrmannr commented 4 months ago

Describe the bug Undefined reference if linking against static library.

Expected behavior It should be possible to link against the static library. All references must be resolved.

Observed behavior No object files for osdp_pcap.c and pcap_gen.c. They should be added to LIB_OSDP_SOURCES instead of LIB_OSDP_UTILS_SRC:

if (CONFIG_OSDP_PACKET_TRACE OR CONFIG_OSDP_PACKET_TRACE)
    list(APPEND LIB_OSDP_SOURCES
        ${CMAKE_CURRENT_SOURCE_DIR}/osdp_pcap.c
    )
endif()

# and later on:
if (CONFIG_OSDP_PACKET_TRACE OR CONFIG_OSDP_PACKET_TRACE)
    list(APPEND LIB_OSDP_SOURCES
        ${PROJECT_SOURCE_DIR}/utils/src/pcap_gen.c
    )
endif()

Additional context Config using CMake:

set(CONFIG_OSDP_PACKET_TRACE ON)
set(CONFIG_OSDP_DATA_TRACE OFF)
set(CONFIG_OSDP_SKIP_MARK_BYTE OFF)
set(CONFIG_DISABLE_PRETTY_LOGGING OFF)
set(CONFIG_OSDP_STATIC_PD OFF)
set(CONFIG_OSDP_LIB_ONLY ON)

A Comprehensive Log file

/usr/bin/ld: ../mylib.so: undefined reference to `osdp_packet_capture_init'
/usr/bin/ld: ../mylib.so: undefined reference to `osdp_capture_packet'
/usr/bin/ld: ../mylib.so: undefined reference to `osdp_packet_capture_finish'
sidcha commented 4 months ago

@rherrmannr please feel free to re-open this issue if does not fix your problem. I didn't test this fix, just eye-balled :)

rherrmannr commented 3 months ago

For me it's working. Thanks :+1: