Search code examples
czephyr-rtos

static declaration of ‘close’ follows non-static declaration static inline int close(int sock)


I have been developing in c for around 6 months and I am very confused about what is going on here at all. I am getting this error when trying to include socket.h header files.

static inline int close(int sock)
{
    return zsock_close(sock);
}

this is the method it seems to have problems with? and I get back this from the build.

In file included from /home/jordan/zephyr/zephyr/include/posix/pthread.h:13:0,
                 from /home/jordan/thrift/src/c/zephyr/mbedtlstest/../../../../include/thrift/os.h:10,
                 from /home/jordan/thrift/src/c/zephyr/mbedtlstest/../../../../include/thrift/types.h:4,
                 from /home/jordan/thrift/src/c/zephyr/mbedtlstest/../../../../include/thrift/ssl/../transport.h:4,
                 from /home/jordan/thrift/src/c/zephyr/mbedtlstest/../../../../include/thrift/ssl/transport.h:4,
                 from /home/jordan/thrift/src/c/ssl/transport.c:1:
/home/jordan/zephyr/zephyr/include/posix/unistd.h:21:12: note: previous declaration of ‘close’ was here

Solution

  • As user3386109 stated, close is a C POSIX library function that is used for closing file descriptors. You can find more information about it here:-

    https://linux.die.net/man/2/close

    The correct way to fix this is to rename your function to something unique that has not been used before.