Martin's technology blog – Perl
Blog content
Active categories:
- Vista (12)
- Office 2007 (1)
- Logitech (1)
- Darwin at work (1)
- Blog (1)
By date:
(No recent posts)
Blog calendar
| Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|
| << Dec | Feb >> | |||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | |
2007-06-19 | Using DateTime on Windows with ActivePerl and Visual Studio 2005
Trying to use Perl's DateTime module on Windows can be somewhat of a challenge, especially since ActivePerl doesn't seem to be packaging it for their PPM.
The solution to that is usually to launch cpan on the command line but in this case that didn't work because the Makefile, when run in the Visual Studio 2005 command prompt, generates DLLs that are dynamically linked to msvcr80.dll. I haven't checked the exact cause--probably something wrong with the manifest,--but as soon as you launch a Perl program that uses DateTime, the following dialog pops up:

(This application has failed to start because MSVCR80.dll was not found. Re-installing the application may fix this problem.)
If you look at the output of the CPAN build, you should see all the tests failing because DateTime cannot be loaded, followed by the path where the objectionable DLL is located:
t/00load................
t/00load................NOK 1# Failed test 'use DateTime;'
# in t/00load.t at line 6.
# Tried to use 'DateTime'.
# Error: Can't load 'C:\Perl\cpan\build\DateTime-0.37\
# blib\arch/auto/DateTime/DateTime.dll' for module DateTime:
# load_file:The specified module could not be found at
# C:/Perl/lib/DynaLoader.pm line 230.
# at C:/Perl/lib/DynaLoader.pm line 49
# BEGIN failed--compilation aborted at t/00load.t line 6.
# Compilation failed in require at (eval 3) line 2.
# BEGIN failed--compilation aborted at (eval 3) line 2.
# Looks like you failed 1 test of 1.
t/00load................dubious
Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 1
Failed 1/1 tests, 0.00% okay
[...]
Installing C:\Perl\site\lib\auto\DateTime\DateTime.bs
Installing C:\Perl\site\lib\auto\DateTime\DateTime.dll
Installing C:\Perl\site\lib\auto\DateTime\DateTime.dll.manifest
Installing C:\Perl\site\lib\auto\DateTime\DateTime.exp
Installing C:\Perl\site\lib\auto\DateTime\DateTime.lib
Installing C:\Perl\site\lib\auto\DateTime\DateTime.pdb
Let's quickly look at the files in question, so we can compare them later. Note the size of DateTime.dll.
C:\Perl\site\lib\auto\DateTime>dir Directory of C:\Perl\site\lib\auto\DateTime 2007-06-19 11:57 0 DateTime.bs 2007-06-19 11:57 13,312 DateTime.dll 2007-06-19 11:57 382 DateTime.dll.manifest 2007-06-19 11:57 797 DateTime.exp 2007-06-19 11:57 1,942 DateTime.lib 2007-06-19 11:57 199,680 DateTime.pdb
The good solution
The easy solution is to make sure that DateTime.dll gets statically linked against the C runtime. So, before you run cpan, set the following environment variable:
set LINK=LIBCMT.LIB
This will link the library against LIBCMT.LIB instead of MSVCRT.LIB and prevent the above runtime error. Installing DateTime with CPAN should now succeed (i.e. no or very few failed tests) and the file size of DateTime.dll should be slightly bigger:
C:\Perl\site\lib\auto\DateTime>dir Directory of C:\Perl\site\lib\auto\DateTime 2007-06-19 12:02 0 DateTime.bs 2007-06-19 12:02 69,632 DateTime.dll 2007-06-19 12:02 382 DateTime.dll.manifest 2007-06-19 12:02 797 DateTime.exp 2007-06-19 12:02 1,942 DateTime.lib 2007-06-19 12:02 715,776 DateTime.pdb
You should now be able to successfully run your Perl program using the speed-optimized native version of DateTime.
The cheap solution
There's another solution to this problem. The DateTime package comes with a Perl-only implementation of the entire functionality. By deleting the C:\Perl\site\lib\auto\DateTime\DateTime.* files, you can force the module to use that version. The performance won't quite be the same but in many cases it might still be good enough for some cases.