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.

Redefinition of timeval in NDK

Other Parts Discussed in Thread: AM5728

Hi,

In both NDK and BSD style sockets, the timeval structure is redefined in socketndk.h. That means that if we're including sys/time.h, we get an error. I had to remove the redefinition from the NDK to build my application. There's a similar problem with bZero and bCopy defines when the application also includes string.h. I had to remove them as well.

Could you please fix these problems in the NDK?

Thanks,

Francis

  • Moving this to the TI-RTOS forum.
  • Hi Francis,

    Just to confirm, are you using the gcc toolchain to build?

    If so, the NDK team is aware of such issues, and will be making a release early next year to resolve this.

    In the meantime, a workaround is to omit the definition of the timeval struct in time.h and just use the NDK one:

    #define _TIMEVAL_DEFINED 1
    
    #include <sys/socket.h>  // brings in NDK’s definition of the timeval struct
    
    #include <sys/time.h>      // won’t define timeval struct if _TIMEVAL_DEFINED is defined

    By having the statements in this order, you should be able to include time.h.  

    For string.h, I do not see any redefinition issue. Are you are building with the option '-D_POSIX_SOURCE'? With the latter defined, my code builds fine when including string.h followed by sys/socket.h. Which version of TIRTOS, NDK and compiler are you using?

    Best regards,

    Vincent

  • Hi Vincent,

    Yes, I'm using the gcc toolchain as I'm targeting the A15 on AM5728.

    The workaround forces me to include the files in that order, but it's not always possible. The headers are not necessarily included at the same place and in the same order in all c files. Anyway. I removed the duplicate definition from the socketndk.h file and it works as expected.

    For the other problem, I can't reproduce it in a simple application. I don't know exactly which file I'm including that's causing this. Also, it's not the same problem, here's the complete error message:

    c:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_9-2015q3\arm-none-eabi\include\string.h: At global scope:
    C:/ti/ndk_2_25_00_09/packages/ti/ndk/inc/bsd/socketndk.h:89:36: error: variable or field 'mmCopy' declared void
    #define bcopy(src, dst, sz) mmCopy((dst), (src), (sz))
    ^
    c:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_9-2015q3\arm-none-eabi\include\string.h:51:7: error: expected primary-expression before 'void'
    void _EXFUN(bcopy,(const void *, void *, size_t));
    ^
    c:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_9-2015q3\arm-none-eabi\include\string.h:51:7: error: expected ')' before 'void'
    C:/ti/ndk_2_25_00_09/packages/ti/ndk/inc/bsd/socketndk.h:88:40: error: variable or field 'mmZeroInit' declared void
    #define bzero(ptr, sz) mmZeroInit((ptr), (sz))
    ^
    c:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_9-2015q3\arm-none-eabi\include\string.h:52:7: error: expected primary-expression before 'void'
    void _EXFUN(bzero,(void *, size_t));
    ^
    c:\ti\ccsv6\tools\compiler\gcc-arm-none-eabi-4_9-2015q3\arm-none-eabi\include\string.h:52:7: error: expected ')' before 'void'

    My workaround is the same for these errors though, I just removed the duplicate bzero and bcopy definitions.

    Francis
  • Hi Francis,

    Thank you for reporting the details. I'll forward this to the NDK team and see if they can reproduce and fix this as part of fixing the other headers.

    Best regards,
    Vincent
  • I filed a bug for this issue to ensure it gets tracked:

    NDK-130 conflicting definitions in NDK for bzero bcopy

    Cheers,

    Steve