[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mingw, ptw32, and struct timespec

From: Eric Blake
Subject: mingw, ptw32, and struct timespec
Date: Wed, 02 Jun 2010 10:50:26 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.4

I'm getting a compilation failure when trying to cross-compile from
Linux to mingw, because I have the mingw pthreads-win32 (ptw32) library
installed (Fedora 13 system, with mingw32-pthreads and mingw32-gcc
packages).  The ptw32 library installs a pthread.h that blindly defines
struct timespec if HAVE_STRUCT_TIMESPEC is not defined:

struct timespec {
        long tv_sec;
        long tv_nsec;

That library also has the nasty behavior of installing a config.h file,
which it then includes as part of pthread.h (recommended practice is
that config.h must NEVER be installed, and that if you are installing a
public header that depends on configuration options, you should install
a header by a different name that only your package will refer to, and
that you should make an extreme effort to make the file be independent
of compiler options that might differ between when your library was
configured vs. when a client of your library is configured).

Meanwhile, the gnulib library provides a replacement struct timespec,
and correctly declares it in the time.h header:

* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
   Or they define it with the wrong member names or define it in
   (e.g., FreeBSD circa 1997).  */
#   include <sys/time.h>
#  else

#   ifdef __cplusplus
extern "C" {
#   endif

#   undef timespec
#   define timespec rpl_timespec
struct timespec
  time_t tv_sec;
  long int tv_nsec;

Unfortunately, the gnulib replacement conflicts with the ptw32 version:

make  all-am
make[1]: Entering directory `/home/remote/eblake/libvirt-tmp/build/src'
  CC     libvirt_util_la-hooks.lo
In file included from ../../src/util/threads-pthread.h:24,
                 from ../../src/util/threads.h:65,
                 from ../../src/conf/domain_conf.h:36,
                 from ../../src/util/hooks.c:36:
/usr/i686-pc-mingw32/sys-root/mingw/include/pthread.h:307: error:
redefinition of 'struct rpl_timespec'
make[1]: *** [libvirt_util_la-hooks.lo] Error 1
make[1]: Leaving directory `/home/remote/eblake/libvirt-tmp/build/src'
make: *** [all] Error 2

I'm not sure of the best fix for this.  A naive fix would be having
gnulib #define HAVE_STRUCT_TIMESPEC in its replacement time.h if it
defined the replacement, but I'm not sure if that is safe for all
possible inclusion orders of <pthread.h> and/or <time.h> within various
source files.  Maybe gnulib's m4/time_h.m4 needs to check whether
<pthread.h> exists and defines struct timespec, and not override struct
timespec in that case?

Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]