Menu

#2272 double definition for "struct timespec"

Known_Feature
upstream
None
Bug
self-service
Unknown
False
2016-11-29
2015-09-18
thomas
No

When I try to compile this file :

#include <unistd.h>
#include <pthread.h>

int main()
{
return 0;
}

I have the error :

In file included from a.c:2:0:
c:\mingw\include\pthread.h:320:8: error: redefinition of 'struct timespec'
 struct timespec {
        ^
In file included from c:\mingw\include\unistd.h:95:0,
                 from a.c:1:
c:\mingw\include\parts\time.h:65:8: note: originally defined here
 struct timespec

Adding :

 #define HAVE_STRUCT_TIMESPEC

after

 struct timespec
{
  /* Period is sum of tv_sec + tv_nsec; use fundamental integer types
   * to avoid 32-bit vs. 64-bit time_t ambiguity.
   */
  long long tv_sec;     /* seconds */
  long      tv_nsec;    /* nanoseconds */
};

in file "C:\MinGW\include\parts\time.h" correct the problem.

Discussion

  • Keith Marshall

    Keith Marshall - 2015-09-18

    Arrrrrrrrrgh!!!!!!!! Please use the preview facility, and correct your markdown before posting, so I don't have to fix it later.

    Anyway, I'm aware of this issue; it is a bug in pthreads-w32, (which doesn't have a configure script, so just makes arbitrary, and possibly bogus assumptions, without performing any requisite feature checks). Adding

    #define HAVE_STRUCT_TIMESPEC
    

    in <parts/time.h> is not a valid solution, (because it would pollute the user namespace). This needs to be fixed in pthreads-w32, a proper solution will require that to support proper build-time configuration, and propagation of that configuration to its installed headers.

    Do please note, that if you are mixing a stock pre-built pthreads-w32 library along with mingwrt-3.21, there is likely a conflict between the struct timespec declared in <parts/time.h>, and the declaration assumed by the pthread library.

     
  • Keith Marshall

    Keith Marshall - 2015-09-18
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,5 +1,6 @@
     When I try to compile this file :
    
    +~~~~
     #include <unistd.h>
     #include <pthread.h>
    
    @@ -7,9 +8,11 @@
     {
     return 0;
     }
    +~~~~
    
     I have the error :
    
    +~~~~
     In file included from a.c:2:0:
     c:\mingw\include\pthread.h:320:8: error: redefinition of 'struct timespec'
      struct timespec {
    @@ -18,13 +21,17 @@
                      from a.c:1:
     c:\mingw\include\parts\time.h:65:8: note: originally defined here
      struct timespec
    +~~~~
    
      Adding :
    
    + ~~~~
      #define HAVE_STRUCT_TIMESPEC
    + ~~~~
    
      after 
    
    + ~~~~
      struct timespec
     {
       /* Period is sum of tv_sec + tv_nsec; use fundamental integer types
    @@ -33,9 +40,6 @@
       long long    tv_sec;     /* seconds */
       long     tv_nsec;    /* nanoseconds */
     };
    +~~~~
    
     in file "C:\MinGW\include\parts\time.h" correct the problem.
    -
    -Bests regards,
    -
    -Thomas
    
    • status: unread --> open
    • assigned_to: Keith Marshall
     
  • Keith Marshall

    Keith Marshall - 2016-11-29
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -25,13 +25,13 @@
    
      Adding :
    
    - ~~~~
    +~~~~
      #define HAVE_STRUCT_TIMESPEC
    - ~~~~
    +~~~~
    
      after 
    
    - ~~~~
    +~~~~
      struct timespec
     {
       /* Period is sum of tv_sec + tv_nsec; use fundamental integer types
    
    • status: open --> upstream
    • Group: OTHER --> Known_Feature
    • Resolution: none --> self-service