NO

Author Topic: same struct in different files  (Read 3883 times)

junko

  • Guest
same struct in different files
« on: February 11, 2015, 03:34:38 PM »
hey everyone
i get this error.

C:\Programs\PellesC\Include\win\winsock2.h(107): error #2123: Redefinition of 'timeval', previously defined at C:\Program\PellesC\Include\sys\time.h(32).

 i'm on pelles 8.0.28.0

this error didn't exist on pellesc 6

Offline Robert

  • Member
  • *
  • Posts: 247
Re: same struct in different files
« Reply #1 on: February 11, 2015, 09:21:46 PM »
If you want to use the winsock2 api, you must include winsock2.h before windows.h.

For a deeper explanation please see

http://sourceforge.net/p/mingw-w64/wiki2/winsock2.h%20include%20order/

Robert Wishlaw


junko

  • Guest
Re: same struct in different files
« Reply #2 on: February 17, 2015, 11:39:01 PM »
i think your answer is wrong because as i said it used to work ok with pelles6
and still works fine with other compilers

anyway i tried your suggest, and it still doesn't work
i get the error:
sys\time.h : redefinition of 'timeval', previously defined at winsock2.h

junko

  • Guest
Re: same struct in different files
« Reply #3 on: February 17, 2015, 11:47:24 PM »
the solution is to include these lines in file winsock2.h
before the declaration of timeval (line 107)
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED

and close with #endif after #define timerclear
Code: [Select]
///insert this in winsock2.h - line 107 (pellesc 8)
#ifndef _TIMEVAL_DEFINED /* this already defined in sys/time.h */
#define _TIMEVAL_DEFINED
struct timeval {
    long tv_sec;
    long tv_usec;
};

#define timerisset(tvp)  ((tvp)->tv_sec || (tvp)->tv_usec)
#define timercmp(tvp,uvp,cmp)  ((tvp)->tv_sec cmp (uvp)->tv_sec || (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
#define timerclear(tvp)  (tvp)->tv_sec = (tvp)->tv_usec = 0
#endif /* _TIMEVAL_DEFINED */
« Last Edit: February 20, 2015, 12:32:29 PM by junko »

Offline Robert

  • Member
  • *
  • Posts: 247
Re: same struct in different files
« Reply #4 on: February 18, 2015, 08:58:14 AM »
i think your answer is wrong because as i said it used to work ok with pelles6
and still works fine with other compilers

anyway i tried your suggest, and it still doesn't work
i get the error:
sys\time.h : redefinition of 'timeval', previously defined at winsock2.h

My apologies for misleading you.

Are you including the time.h header in your program or is it being pulled in by another header?

Do you need the time.h header?