same struct in different files

Started by junko, February 11, 2015, 03:34:38 PM

Previous topic - Next topic

junko

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

Robert

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

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

#3
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

///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 */

Robert

Quote from: junko 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

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?