#1568 Improper timeval ifdef check before defining in winsock2.h

closed-invalid
nobody
non-mingw (19)
2014-09-15
2011-08-06
No

winsock2.h reads

#if !(defined (__INSIDE_CYGWIN__) || (__INSIDE_MSYS__))
#ifndef _TIMEVAL_DEFINED /* also in sys/time.h */
#define _TIMEVAL_DEFINED
struct timeval {
long tv_sec;
long tv_usec;
};

however, my time.h reads

#if !(defined (__INSIDE_CYGWIN__) || (__INSIDE_MSYS__))
#ifndef _TIMEVAL_DEFINED /* also in sys/time.h */
#define _TIMEVAL_DEFINED
struct timeval {
long tv_sec;
long tv_usec;
};

therefore, the define by time.h will not be found by winsock2.h.

Checking for _TIMEVAL_DEFINED is obviously not an option because sys/time.h can and will (in my case) be included (by another mingw file) before winsock2.h. You also have no right to start defining timeval, just include it.

I propose just including <ctime>. A possible sollution is included in attachment.

ives ~/ $ gcc -v
Using built-in specs.
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)

Discussion

  •  
    Attachments
  • In case anyone cares, the error that caused me to find this is

    In file included from /usr/include/sys/select.h:46,
    from /usr/include/sys/types.h:220,
    from /usr/include/stdlib.h:320,
    from /usr/lib/gcc/i586-mingw32msvc/4.4.4/include/c++/cstdlib:68,
    from /usr/lib/gcc/i586-mingw32msvc/4.4.4/include/c++/bits/stl_algo.h:60,
    from /usr/lib/gcc/i586-mingw32msvc/4.4.4/include/c++/algorithm:62,
    from src/HostEntry.cpp:39:
    /usr/include/bits/time.h:75: error: redefinition of 'struct timeval'
    /usr/lib/gcc/i586-mingw32msvc/4.4.4/../../../../i586-mingw32msvc/include/winsock2.h:109: error: previous definition of 'struct timeval'

     
  • Earnie Boyd
    Earnie Boyd
    2011-08-06

    • status: open --> pending
     
  • Earnie Boyd
    Earnie Boyd
    2011-08-06

    You need to give us a small test program that demonstrates the issue. We can't guess what you've done wrong so you need to show us.

     
  • I think I figured it out.

    The software I was compiling had -I/usr/local/include -I/usr/include switches for their mingw build, which obviously isn't a good idea. This is probably also the cause of the other bug.

     
    • status: pending --> open
     
  • Keith Marshall
    Keith Marshall
    2011-08-06

    • labels: --> non-mingw
    • priority: 5 --> 1
    • status: open --> closed-invalid
     
  • Keith Marshall
    Keith Marshall
    2011-08-06

    As noted on your other ticket, this seems to be a consequence of mixing MinGW and Linux native headers in the same build. This isn't just a bad idea -- it is invalid usage.