bug-gnulib
[Top][All Lists]
Advanced

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

failure to include C++'s <ctype> when gmtime and localtime are replaced


From: Alexandre Duret-Lutz
Subject: failure to include C++'s <ctype> when gmtime and localtime are replaced by gnulib
Date: Thu, 18 Jul 2013 22:17:40 +0200

Hi,

My C++ code uses a few modules of gnulib and has to be
cross-compilable with MinGW.

Using gnulib 312af25ba220ccff068245f0dc698e9bcc8f03f8, my
cross-compilation builds fail with:

In file included from /usr/include/c++/4.6/bits/locale_facets_nonio.h:39:0,
from /usr/include/c++/4.6/locale:43,
from escape.cc:29:
/usr/include/c++/4.6/ctime:72:11: error: '::gmtime' has not been declared
/usr/include/c++/4.6/ctime:73:11: error: '::localtime' has not been declared


Header <ctime> includes <time.h> and does something like this:

#include <time.h>
#undef gmtime
#undef localtime
namespace std
{
  using ::gmtime;
  using ::localtime;
} // namespace

So it will only work if the functions gmtime and localtime actually exist.

I'm cross-compiling to --host=i686-w64-mingw32 so the logic in gettimeofday.m4
results in:

configure:14457: checking whether gettimeofday clobbers localtime buffer
configure:14506: result: guessing yes

causing the following to be emitted in config.h:

  #define gmtime rpl_gmtime
  #define localtime rpl_localtime

Consequently the actual functions declared in the system's <time.h>
are now declared as rpl_gmtime and rpl_localtime, and <ctype> will not
find the gmtime and localtime functions.


The worst part of this is that actually my code does not use gmtime() or
localtime(), and I don't think any of the gnulib modules I use (argmatch,
argp, error, gethrxtime, isatty, mkstemp, mkstemps, progname, stpcpy,
sys_wait) really require these functions.  I can see that the gethrxtime module
requires the gettime module which in turns requires the gettimeofday module,
but the latter module is only used for its gettimeofday() function.


It seems this C++ crosscompilation issue was already reported by John Eaton
two years ago 
<http://lists.gnu.org/archive/html/bug-gnulib/2011-11/msg00388.html>
but without reaching a conclusion.

I applied the patch given by JWE in that thread. I had to fix the
prototype of gmtime()
and localtime() in time.in.h because these functions should take only one
argument, and I also had to add AC_SUBST for HAVE_GMTIME and HAVE_LOCALTIME
for the case where gl_GETTIMEOFDAY_REPLACE_LOCALTIME is not called.
Then all my builds became green again :-)

The fixed patch with a ChangeLog (in his name) is attached.

-- 
Alexandre Duret-Lutz

Attachment: 0001-gettimeofday-fix-C-crosscompilation.patch
Description: Binary data


reply via email to

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