obgm / libcoap

A CoAP (RFC 7252) implementation in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing symbol 'coap_accept_endpoint' error when compiling with ENABLE_TCP=OFF

WndDezorian opened this issue · comments

Environment

  • libcoap version: v4.2.1-898-gdbf78b5 Current develop branch, commit dbf78b5
  • Build System: CMake
  • Operating System: Linux
  • Operating System Version: Fedora Linux
  • Hosted Environment: None

Problem Description

Library compiles correctly, but fails to link with a missing symbol coap_accept_endpoint error.
I suspect this is because the call to coap_accept_endpoint in src/net.c:1993 is not wrapped in a #if !COAP_DISABLE_TCP guard, unlike the earlier call at line 1913 or the function definition at line 1884.

I suspect adding a #if !COAP_DISABLE_TCP guard around the block starting at line 1990 would correct the issue:

        if ((sock->flags & COAP_SOCKET_WANT_ACCEPT) &&
            (events[j].events & EPOLLIN)) {
          sock->flags |= COAP_SOCKET_CAN_ACCEPT;
          coap_accept_endpoint(endpoint->context, endpoint, now);
        }

Expected Behavior

Expect the library to link without errors when ENABLE_TCP = OFF

Actual Behavior

Library compiles, but fails to link with a missing symbol error.

Steps to reproduce

git clone https://github.com/obgm/libcoap.git
git checkout dbf78b526fe7ee9dbb1a4bce1bcc62a01fff161f #Current develop branch head
cd libcoap
mkdir build
cd build
cmake -DENABLE_TCP=OFF -DENABLE_EXAMPLES=ON ..
make

Build will fail when linking the examples

Code to reproduce this issue

No code needed beyond the built-in examples

Debug Logs

...
[ 72%] Built target coap-3
[ 75%] Building C object CMakeFiles/coap-client.dir/examples/coap-client.c.o
[ 77%] Linking C executable coap-client
/usr/bin/ld: libcoap-3.a(net.c.o): in function `coap_io_do_epoll':
/tmp/libcoap/src/net.c:1993: undefined reference to `coap_accept_endpoint'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/coap-client.dir/build.make:100: coap-client] Error 1
make[1]: *** [CMakeFiles/Makefile2:123: CMakeFiles/coap-client.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Other items if possible

N/A

Thanks for raising this.

I suspect adding a #if !COAP_DISABLE_TCP guard around the block starting at line 1990 would correct the issue:

Yes, this fixes the issue which only occurs when EPOLL is available. I will get a fix raised in due course.

See #1113 for a fix.

I confirm that fixed the problem for me. Thank you!

Thanks for confirming.