This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PROCESSOR-SDK-AM64X: <sys/select.h> Header and LwIP

Part Number: PROCESSOR-SDK-AM64X


Hello,

we have some problems using the header <sys/select.h> Header. If you use this in combination with LwIP Stack of the processor SDK the struct timeval ist multiple defined.

The Error-Message:

/-sdk-path-/source/networking/lwip/lwip-stack/src/include/lwip/sockets.h:522:8: error: redefinition of 'timeval'
struct timeval {
^
/home/-user-/ti/ti-cgt-armllvm_1.3.0.LTS/include/c/sys/_timeval.h:49:8: note: previous definition is here
struct timeval {
^

Should this header not be used?

This might also be a problem with the AM243 SDK.

Greetings 

Fabian

  • Hi Fabian,

    In mcu_plus_sdk_am64x_08_01_00_36\source\networking\lwip\lwip-stack\src\include\lwip\sockets.h, make the following change. It should solve your problem.

    /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
    * by your system, set this to 0 and include <sys/time.h> in cc.h */
    #ifndef LWIP_TIMEVAL_PRIVATE
    #define LWIP_TIMEVAL_PRIVATE 1 --> 0
    #endif

    Best regards,

    Ming

  • Hi Ming,

    will this be included in the next SDK release? 

    Best Regards 

    Fabian

  • Hi Fabian,

    It meant to be customized by users. If we change it 0, it will not work for the case without sys/select.h.

    Best regards,

    Ming 

  • Hi Ming,

    still this is a little bit confusing for me. should all the options be included in the lwipopts.h file? 

  • Hi Ming, sadly it does not fix the problem as I just now noticed. After changing the define I cannot build the library anymore. 

    source/networking/lwip/lwip-stack/src/include/lwip/sockets.h:601:24: error: declaration of 'struct timeval' will not be visible outside of this function [-Werror,-Wvisibility]
                    struct timeval *timeout);
                           ^
    1 error generated.

    Any Idea on that? 

  • Hi Fabian,

    It is really a stuff one, because the lwip library and your example are built separately, so it has to be included on both lwip lib and your application code. Here is a workaround in sockets.h:

    /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
    * by your system, set this to 0 and include <sys/time.h> in cc.h */
    #ifndef LWIP_TIMEVAL_PRIVATE
    #define LWIP_TIMEVAL_PRIVATE 1
    #endif

    #if LWIP_TIMEVAL_PRIVATE
    #ifndef _SYS__TIMEVAL_H_
    #define _SYS__TIMEVAL_H_
    struct timeval {
    long tv_sec; /* seconds */
    long tv_usec; /* and microseconds */
    };
    #endif
    #endif /* LWIP_TIMEVAL_PRIVATE */

    It will get rid of the timeval redefine issue, but the fd_set will pop up. The only way to workaround that issue is comment out the following lines in sys/select.h

    ///typedef struct fd_set {
    /// __fd_mask __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
    ///} fd_set;

    I have tested it with MCU+ SDK 08.01.00.36. It did pass the build for both library and application.

    I know it looks ugly, but unfortunately it seems to be the only way. Disappointed

    Best regards,

    Ming

  • Hi Ming,

    but the sys/select.h header is shipped with the compiler and not present in the SDK. We can not change this header on each development computer of your devs. 

    Sadly we can not use this also as a temporary workaround.

  • Hi Fabian,

    Understood. Here is another workaround w/o changes in sys/select.h:

    make the following changes in mcu_plus_sdk_am64x_08_01_00_36\source\networking\lwip\lwip-stack\src\include\lwip\sockets.h:

    #include <sys/select.h> ///MW (line 42)

    ...

    ///MW typedef struct fd_set (line 483 - 486)
    ///MW {
    ///MW unsigned char fd_bits [(FD_SETSIZE+7)/8];
    ///MW } fd_set; 

    ...

    #define LWIP_TIMEVAL_PRIVATE 0 ///MW (line 520)

    Best regards,

    Ming

  • Hi Ming,

    yesterday I found a similar fix as you suggest.

    But you dont need to comment fd_set out.

    You can just leave it since 

    /* FD_SET used for lwip_select */
    #ifndef FD_SET  //from line 466 in sockets.h
    #undef  FD_SETSIZE
    
    .... // all the fd_set, FD_SET, ...
    
    #endif

    the ifndef will not define all the fd_set stuff if it is already provided.

    (Also we keeped your change for privating the timeval struct)

    We included sys/select.h in the lwipopts.h header. 

    I think a similar fix should be provided with the next SDK release.

    Best regards 

    Fabian

  • Hi Fabian,

    Got it. I will file a ticket against it .

    Best regards,

    Ming