Opened 15 years ago

Closed 13 years ago

Last modified 12 years ago

#1740 closed Bugs (fixed)

date_time includes <windows.h>

Reported by: Anteru@… Owned by: az_sw_dude
Milestone: Boost 1.36.0 Component: date_time
Version: Boost 1.39.0 Severity: Problem
Keywords: windows.h date_time Cc:

Description

The header <boost/date_time/filetime_functions.hpp> includes <windows.h> by default, and there is no way to turn this off (e.g. BOOST_USE_WINDOWS_H). This is a problem as this brings in the min,max,ERROR,etc. macros in. (This header is included if you include <boost/date_time.hpp>

As date_time has to be compiled anyway, it would be very nice to have this functionality in the library somewhere and not include <windows.h>.

Attachments (1)

date_time.patch (6.8 KB ) - added by emilm@… 14 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by anonymous, 15 years ago

This is also breaking Asio, as Asio wants to include winsock, see: http://permalink.gmane.org/gmane.comp.lib.boost.devel/172990

in reply to:  1 comment:2 by Anteru, 15 years ago

Forgot to set the name -- this comment is from me, Anteru

comment:3 by anonymous, 14 years ago

This is a very serious bug for us as well as it completely breaks our entire project. It does not appear that any code which uses Windows.h is required to be inline or even public. We have yet to find a work around which allows us to build using 1.35 and have been stuck on 1.34.1.

A fix soon would be greatly appreciated.

by emilm@…, 14 years ago

Attachment: date_time.patch added

comment:4 by emilm@…, 14 years ago

Please find attached a patch to solve this issue and the test report of the library on the compiler I have at my disposal. I have taken precautions in order to ensure it will work on x64 Windows (please see comments related to the conversion between FILETIME and int64) and I see no reason it should have changed for other platforms, but only testing will tell.

comment:5 by Andrey Semashev, 14 years ago

Resolution: fixed
Status: newclosed

comment:6 by anonymous, 13 years ago

Keywords: windows.h date_time added
Resolution: fixed
Status: closedreopened
Version: Boost 1.35.0Boost 1.39.0

If you do include windows.h anywhere in boost, you need the following two lines of code just above it:

#undef  WIN32_LEAN_AND_MEAN  // add this...
#define WIN32_LEAN_AND_MEAN  // ...and this
#include <windows.h>

Otherwise, if some other 3rd party lib includes <windows.h>, it will break the build unless the header files are in a very specific order, which is extremely tedious to maintain.

in reply to:  6 comment:7 by anonymous, 13 years ago

Resolution: fixed
Status: reopenedclosed

Replying to anonymous:

If you do include windows.h anywhere in boost, you need the following two lines of code just above it:

#undef  WIN32_LEAN_AND_MEAN  // add this...
#define WIN32_LEAN_AND_MEAN  // ...and this
#include <windows.h>

Otherwise, if some other 3rd party lib includes <windows.h>, it will break the build unless the header files are in a very specific order, which is extremely tedious to maintain.

First, Boost.DateTime no longer includes windows.h by default. You can explicitly enable it to include windows.h by defining BOOST_USE_WINDOWS_H.

Second, defining WIN32_LEAN_AND_MEAN will disable quite a few components in windows.h. Boost.DateTime is in no position to enforce this decision in its headers. If you want windows.h to behave like when WIN32_LEAN_AND_MEAN is defined, you should define it in your project, before including any headers.

Note: See TracTickets for help on using tickets.