Will there be a CCTZ version for Microsoft Windows?

394 views
Skip to first unread message

Susanne Meyer

unread,
Mar 13, 2016, 10:39:15 PM3/13/16
to cctz
Hi there,

I'm very pleased to here from your new CCTZ C++ library!

Because I'm searching for a long time for a small footprint C or C++ library which is able to read from TZ timezone database files directly. I was disappointed to read that CCTZ currently only works on Linux and Mac OS.

Will there be ever a CCTZ C++ version which is Microsoft Windows compatible?

The TZ-Timezone database support for Linux and C/C++ is already very strong. But for Windows there is only ICU (http://site.icu-project.org). Which isn't an ideal solution because it is spread over several ICU libraries you have to import and later deliver with your application. And because the TZ timezone database is compiled inside the ICU DLLs, to update the TZ timezone database to its newest version you have to wait for the next ICU library release and compile to your application again. :-(

So it would be great to have a small footprint Windows compatible C/C++ library which can read from the TZ Ianna Timezone files (for example "tzdata2016a.tar.gz") directly. So you only have to update the TZ-files to keep your application up to date!

Susan

Greg Miller

unread,
Mar 14, 2016, 9:34:43 PM3/14/16
to Susanne Meyer, cctz
I don't have a Windows machine handy to test, but the last time I tested, cctz did work with the IANA data files on Windows. The Windows support that is lacking (and is mentioned on the github page) is Windows support that uses the non-IANA data from Windows (wherever that is).

Are you able to give cctz a try in your Windows application and report back here? If it needs a couple of tweaks, we'll be happy to help you get it working.

(Note: this is a very new mailing list, so there's probably nobody else on here to chime in with other details about Windows support yet).

Greg

--
https://github.com/google/cctz
---
You received this message because you are subscribed to the Google Groups "cctz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cctz+uns...@googlegroups.com.
To post to this group, send email to cc...@googlegroups.com.
Visit this group at https://groups.google.com/group/cctz.
To view this discussion on the web visit https://groups.google.com/d/msgid/cctz/ff467ab0-1ec9-4700-b367-0b0aa55496c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted
Message has been deleted

Susanne Meyer

unread,
Mar 16, 2016, 7:29:04 AM3/16/16
to cctz, gr...@mllr.cc
Hi Greg,

that are really good news!

So I made a quick test compile with Visual Studio 2015 on Windows and got these two error messages in 'cctz_libc.cpp'.

cctz_libc.cpp(65): error C2065: "timezone": undeclared identifier:

Line 65: bd.offset = OFFSET(tm);


cctz_libc.cpp(66): error C2065: "tzname": undeclared identifier:

Line 66: bd.abbr = ABBR(tm);


This is probably because in the macro definitions of 'OFFSET' and 'ABBR' the compiler can't find the declarations of the identifiers 'timezone' and 'tzname':

Line 39: #else
Line 40: # define OFFSET(tm) (timezone + ((tm).tm_isdst > 0 ? 60 * 60 : 0))
Line 41: # define ABBR(tm)   (tzname[(tm).tm_isdst > 0])

How can I solve this issue?

Another question is where to put the Ianna TZ database files? Is it sufficient to put them in the application folder? Does cctz read the original TZ archive file (for example tzdata2016b.tar.gz), or the extracted files?

Greg Miller

unread,
Mar 16, 2016, 8:16:20 AM3/16/16
to Susanne Meyer, cctz
This page (https://msdn.microsoft.com/en-us/library/aa246456(v=vs.60).aspx) seems to indicate that the 'timezone' and 'tzname' globals are named '_timezone' and '_tzname'. (They should be set by _tzset(), which I assume is called by localtime() on Windows).

To test if this fixes the problem, could you modify src/cctz_libc.cc on lines 39 and 40 to add the leading underscores to those names to see if it then compiles?

Thanks,
Greg

--
https://github.com/google/cctz
---
You received this message because you are subscribed to the Google Groups "cctz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cctz+uns...@googlegroups.com.
To post to this group, send email to cc...@googlegroups.com.
Visit this group at https://groups.google.com/group/cctz.

Susanne Meyer

unread,
Mar 16, 2016, 9:42:18 AM3/16/16
to cctz, gr...@mllr.cc
Adding a leading underscore to _timzone and _tzname worked! After that cctz_libc.cpp and the other cctz source files compile without any error on Windows.

Now I tried your examples 'hello.cpp' and 'example1.cpp' but both fail to load the timezone file. cctz::LoadTimeZone() returns the error string:

/usr/share/zoneinfo/Australia/Sydney: No such file or directory (hello.cpp)
/usr/share/zoneinfo/America/Los Angeles: No such file or directory (exemple.cpp)

The original Ianna TZ database file 'tzdata2016b.tar.gz' is unzipped into the example application folder. But in the original TZ data archive there is for example no file named 'Australia' which is neede for 'hello.cpp'. Only a file named 'australasia' is in the original tzdata file.

Can you please give some further help?
1. How to run the cctz example programs on Windows?
2. How to change the TZ database files folder and make them accessible for cctz?

Thanks,
Susan

Bradley White

unread,
Mar 16, 2016, 2:21:39 PM3/16/16
to Susanne Meyer, cctz, gr...@mllr.cc
Hi Susanne,

On Wed, Mar 16, 2016 at 9:42 AM, 'Susanne Meyer' via cctz <cc...@googlegroups.com> wrote:
Adding a leading underscore to _timzone and _tzname worked! After that cctz_libc.cpp and the other cctz source files compile without any error on Windows.

Excellent.  We'll make that change in the repository.  Thanks.
 
Now I tried your examples 'hello.cpp' and 'example1.cpp' but both fail to load the timezone file. cctz::LoadTimeZone() returns the error string:

/usr/share/zoneinfo/Australia/Sydney: No such file or directory (hello.cpp)
/usr/share/zoneinfo/America/Los Angeles: No such file or directory (exemple.cpp)

The original Ianna TZ database file 'tzdata2016b.tar.gz' is unzipped into the example application folder. But in the original TZ data archive there is for example no file named 'Australia' which is neede for 'hello.cpp'. Only a file named 'australasia' is in the original tzdata file.

Can you please give some further help?
1. How to run the cctz example programs on Windows?
2. How to change the TZ database files folder and make them accessible for cctz?

There are two issues there.

(1) You'll need to either compile the zoneinfo data files using the "zic" tool (e.g., compiling "australasia" creates "Australia/Sydney"), or you'll need to fetch precompiled zoneinfo files from somewhere.

(2) If the location of those compiled zoneinfo files is not /usr/share/zoneinfo, you will need to set the TZDIR environment variable to tell cctz where to look for them.

After that it sounds like the example programs would run successfully for you.

Bradley
Message has been deleted

Susanne Meyer

unread,
Mar 16, 2016, 11:21:30 PM3/16/16
to cctz, b...@acm.org
Hi Bradley,

cctz works flawless now on Windows (as first tests are suggesting)!

As you said, compiling the tz database files with the 'zic' compiler did the job. Also setting the 'TZDIR' environment variable to tell cctz where to look for the tz database files works fine.

Greg and Bradley, many thanks for your help and again for your great cctz library!

Susan

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

For other novices like me, here is a short discription how to get the 'zic.exe' compiler for Windows:

1. Install 'Cygwin' on Windows
2. Get 'zic.exe' from 'cygwin' installation folder. For example c:\cygwin64\use\sbin
3. 'zic.exe' needs 'cygwin1.dll' in the same folder to work. Get it from c:\cygwin64\bin
4. Copy 'zic.exe' and 'cygwin1.dll' into your tz database files folder with the unzipped tz database archive files.
4. With 'zic.exe' now you can compile the database files one after another: For example 'zic.exe northamerica'.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Greg and Bradley,

if you like to optimise cctz for Windows a little further. This is the full list of Visual Studio 2015 C++ compiler warning messages:

You can suppress the 'error C4496' message by adding in front of your cc-files:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

1. cctz_libc.cpp(61): error C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

2. cctz_libc.cpp(65): error C4996: '__timezone': This function or variable may be unsafe. Consider using _get_timezone instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

3. cctz_libc.cpp(66): error C4996: '__tzname': This function or variable may be unsafe. Consider using _get_tzname instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

4. cctz_libc.cpp(69): error C4996: 'gmtime': This function or variable may be unsafe. Consider using gmtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

5. cctz_libc.cpp(120): warning C4244: "Initialising": Convert from "time_t" to "int", possible data lost

6. cctz_info.cpp(171): warning C4244: "Initialising": Convert from "int64_t" to "int", possible data lost

7. cctz_info.cpp(171): warning C4244: "Initialisierung": Convert from "int64_t" to "const int", possible data lost

8. cctz_info.cpp(437): warning C4267: "Argument": Convert from "size_t" to "long", possible data lost

9. cctz_info.cpp(652): error C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

10. cctz_info.cpp(657): error C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

11. cctz_info.cpp(665): error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

12. cctz_info.cpp(743): warning C4244: "=": Convert from "int64_t" to "int", possible data lost

13. cctz_info.cpp(758): warning C4244: "=": Convert from "int64_t" to "int", possible data lost

14. src\cctz_info.cpp(760): warning C4244: "=": Convert from "int64_t" to "int", possible data lost

15. cctz_info.cpp(788): warning C4267: "Initialisierung": Convert from "size_t" to "int32_t", possible data lost

16. cctz_info.cpp(788): warning C4267: "Initialisierung": Convert from "size_t" to "const int32_t", possible data lost

17. cctz_info.cpp(823): warning C4244: "Argument": Convert from "__int64" to "int", possible data lost

18. cctz_info.cpp(834): warning C4267: "Initialisierung": Convert from "size_t" to "int32_t", possible data lost

19. cctz_info.cpp(834): warning C4267: "Initialisierung": Convert from "size_t" to "const int32_t", possible data lost

20. cctz_info.cpp(861): warning C4244: "Argument": Convert from "__int64" to "int", possible data lost

21. cctz_cnv.cpp(32): error C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Bradley White

unread,
Mar 23, 2016, 6:37:34 PM3/23/16
to Susanne Meyer, CCTZ
On Wed, Mar 16, 2016 at 10:34 PM, 'Susanne Meyer' via cctz <cc...@googlegroups.com> wrote:
if you like to optimise cctz for Windows a little further. This is the full list of Visual Studio 2015 C++ compiler warning messages:

Thanks Susanne.  We will apply tweaks to (hopefully) address these issues in an upcoming release.

On a slightly related issue, we have had a report from another Windows user of a need for "export definitions" for symbols exported from the library.  Do you know what you are doing to avoid/satisfy that requirement?

thanks,
Bradley

Susanne Meyer

unread,
Mar 24, 2016, 8:57:40 AM3/24/16
to cctz, b...@acm.org
Bradley you wrote:
"On a slightly related issue, we have had a report from another Windows user of a need for "export definitions" for symbols exported from the library.  Do you know what you are doing to avoid/satisfy that requirement?".

For my programming skills building a dynamic link library in C++ isn't an easy job. Especially if it's from source I didn't build myself. I tried a few times to build the cctz library but the resulting DLL was always only 46 kb big. Which indicated to me that there went something seriously wrong. So I gave up on this and thought I'm too silly for that task.

So I'm by no means an expert on building a C++ DLL on Windows. I tried to follow this Microsoft article but failed: https://msdn.microsoft.com/de-de/library/ms235636.aspx
Quite complicated for my ears especially when I compare it with the simple BAZEL 'BUILD' script file which is provided with the cctz source files :-(

So till now I only use and compile the cctz source files with my application. As written before this works fine except for the error message 'C4496' which can be suppressed by the macro '_CRT_SECURE_NO_WARNINGS'. This error exists because Microsoft says that localtime and probably the other functions too which cause this error are not thread save. Because my application doesn't do multi threads this isn't an issue for me. Meanwhile I read that the Linux POSIX C++ thread save replacement for localtime() is localtime_r(), whereas for Microsoft Visual C++ it is localtime_s(). So switching to these thread save functions would make sense.

SorryI couldn't help you with the Windows DLL building problem. Please ask a professional Windows C++ programmer for this. This will no big deal for him.

Susan

Bradley White

unread,
Oct 25, 2017, 10:43:24 PM10/25/17
to cctz
On Wednesday, March 16, 2016 at 11:21:30 PM UTC-4, Susanne Meyer wrote:
cctz works flawless now on Windows (as first tests are suggesting)!

As you said, compiling the tz database files with the 'zic' compiler did the job. Also setting the 'TZDIR' environment variable to tell cctz where to look for the tz database files works fine.

Update: We have now included pre-compiled zoneinfo files in the CCTZ distribution, so Windows users should just be able to copy those.

For other novices like me, here is a short discription how to get the 'zic.exe' compiler for Windows:

1. Install 'Cygwin' on Windows
2. Get 'zic.exe' from 'cygwin' installation folder. For example c:\cygwin64\use\sbin
3. 'zic.exe' needs 'cygwin1.dll' in the same folder to work. Get it from c:\cygwin64\bin
4. Copy 'zic.exe' and 'cygwin1.dll' into your tz database files folder with the unzipped tz database archive files.
4. With 'zic.exe' now you can compile the database files one after another: For example 'zic.exe northamerica'.

For what it's worth, if you install Cygwin you should just be able to use their zoneinfo files from <cygwin-root>/usr/share/zoneinfo.  No need to mess with zic.exe yourself.

Bradley
Reply all
Reply to author
Forward
0 new messages