Background
Its been quite interesting reading all the many varied writeups and tutorials on building modules for Windows.
To keep this focused, I know about PPM. The sole reason I have begun down this path is that modules provided on the ActiveState repository, are often several versions behind CPAN. (which is often months and sometimes even years).
I realise that building modules for Win32 is a difficult task, but I'm willing to do whatever necessary to figure this out. Plus i have been finding this quite interesting so far. The trigger for this was my interest in getting Win32::API. And File::Spec is a dependancy of it that needs a compiler
Also, to clarify, I don't have any prior knowledge or experience compiling c code. But I'm keen to learn, and so far, I've never found a learning adventure that didn't provide some kind of rewards.
Building PathTools-3.30
I have started with PathTools, which I believe should work on Windows. (I realise that there will always be some modules that just won't work on windows, and I accept that.)
I have browsed the very helpful tutorials on modules,
Installing Modules but times have definitely moved on since these were written. I went looking for Visual Studio 2003, but found its been replaced twice, So I downloaded the Visual Studio 2008 Express package.
Making PathTools
Visual Studio installed fine, and nmake was detecting it. "Sweet!" I thought.
C:\temp\file_spec\PathTools-3.30>perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for Cwd
C:\temp\file_spec\PathTools-3.30>nmake
Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
cp lib/File/Spec/Mac.pm blib\lib\File\Spec\Mac.pm
cp lib/File/Spec/OS2.pm blib\lib\File\Spec\OS2.pm
cp lib/File/Spec/VMS.pm blib\lib\File\Spec\VMS.pm
cp lib/File/Spec/Cygwin.pm blib\lib\File\Spec\Cygwin.pm
cp lib/File/Spec/Epoc.pm blib\lib\File\Spec\Epoc.pm
cp lib/File/Spec/Functions.pm blib\lib\File\Spec\Functions.pm
cp lib/File/Spec.pm blib\lib\File\Spec.pm
cp Cwd.pm blib\lib\Cwd.pm
cp lib/File/Spec/Unix.pm blib\lib\File\Spec\Unix.pm
cp lib/File/Spec/Win32.pm blib\lib\File\Spec\Win32.pm
C:\Perl\bin\perl.exe C:\Perl\lib\ExtUtils\xsubpp -typemap C:\
+Perl\lib\ExtUtils\typemap Cwd.xs > Cwd.xsc && C:\
Perl\bin\perl.exe -MExtUtils::Command -e mv Cwd.xsc Cwd.c
cl -c -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSO
+LE -DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED -D
USE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL
+_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -
MD -Zi -DNDEBUG -O1 -DVERSION=\"3.30\" -DXS_VERSION=\"3.30\" "-IC
+:\Perl\lib\CORE" Cwd.c
Cwd.c
Cwd.xs(89) : warning C4996: 'getcwd': The POSIX name for this item is
+deprecated. Instead, use the ISO C++ conformant na
me: _getcwd. See online help for details.
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\direct
+.h(121) : see declaration of 'getcwd'
Cwd.xs(77) : warning C4101: 'symlink' : unreferenced local variable
Running Mkbootstrap for Cwd ()
C:\Perl\bin\perl.exe -MExtUtils::Command -e chmod 644 Cwd.bs
C:\Perl\bin\perl.exe -MExtUtils::Mksymlists -e "Mksymlists('N
+AME'=>\"Cwd\", 'DLBASE' => 'Cwd', 'DL_FUNCS' => {
}, 'FUNCLIST' => [], 'IMPORTS' => { }, 'DL_VARS' => []);"
link -out:blib\arch\auto\Cwd\Cwd.dll -dll -nologo -nodefaultli
+b -debug -opt:ref,icf -libpath:"C:\Perl\lib\CORE"
-machine:x86 Cwd.obj C:\Perl\lib\CORE\perl58.lib oldnames.lib kern
+el32.lib user32.lib gdi32.lib winspool.lib comdlg
32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib u
+uid.lib ws2_32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib msvcrt.lib -def:Cwd.def
Creating library blib\arch\auto\Cwd\Cwd.lib and object blib\arch\au
+to\Cwd\Cwd.exp
C:\Perl\bin\perl.exe -MExtUtils::Command -e chmod 755 blib\arc
+h\auto\Cwd\Cwd.dll
C:\Perl\bin\perl.exe -MExtUtils::Command -e cp Cwd.bs blib\arc
+h\auto\Cwd\Cwd.bs
C:\Perl\bin\perl.exe -MExtUtils::Command -e chmod 644 blib\arc
+h\auto\Cwd\Cwd.bs
C:\temp\file_spec\PathTools-3.30>
Then came the problems
C:\temp\file_spec\PathTools-3.30>nmake test
Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harn
+ess(0, 'blib\lib', 'blib\arch')" t/*.t
t/crossplatform....ok
10/71 skipped: various reasons
t/cwd..............ok
2/30 skipped: various reasons
t/Functions........ok
t/rel2abs2rel......ok
t/Spec.............ok
126/598 skipped: various reasons
t/taint............ok
t/tmpdir...........ok
t/win32............Undefined subroutine &Cwd::getdcwd called at t/win3
+2.t line 22.
t/win32............ok 1/4# Looks like you planned 4 tests but only ran
+ 1.
# Looks like your test died just after 1.
t/win32............dubious
Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 2-4
Failed 3/4 tests, 25.00% okay
Failed Test Stat Wstat Total Fail List of Failed
----------------------------------------------------------------------
+---------
t/win32.t 255 65280 4 6 2-4
138 subtests skipped.
Failed 1/8 test scripts. 3/731 subtests failed.
Files=8, Tests=731, 3 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00
+ CPU)
Failed 1/8 test programs. 3/731 subtests failed.
NMAKE : fatal error U1077: 'C:\Perl\bin\perl.exe' : return code '0xff'
Stop.
So... win32.t is failing. (plus others which I was soon to find out) So I ran it directly using this:
C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib\lib', 'blib\arch')" t/win32.t
Then I see the real error. (A pop-up msg)
perl.exe - unable to Locate Component
This application has failed to start because MSVCR90.dll was not found
+. Re-installing the application may fix this problem
So I give Microsoft the benefit of the doubt, I tried reinstalling Perl. no joy. Same error
Then I tried copying the dll into my temp directory just to see what happens. New error this time:
MS Visual C++ Runtime Library
Program: C:\Perl\bin\perl.exe
R6034
An Application has made an attempt to load the C runtime library incor
+rectly.
And finally the questions
- Why did Visual Studio compile the module with a dependancy on MSVCR90.dll?
- Is there anything in the header c files, or makefile, or config.pm file I can edit so that it compiles a fully portable Win32 dll?
- If I were to ditch Visual Studio 2008, and go with MinGW, how do I set up the environment? I couldn't seem to get nmake or MinGW's version of make to find the compiler.
- If anyone here has tried both MS VisualStudio and the gcc tools to compile Perl modules specifically for Win32, which do you prefer and why?
Update:
Well, I managed to get MinGW working, albeit, until it was actually working it was a bit touch and go...
I kept trying various things, and I think my final working result was due to the following. I've jotted them down below for anyone else whos interested.
Run
perl -V:make and
perl -V:cc, if they still report
make='nmake'; and
cc='cl'; respectively, Perl won't create the
Makefile file properly (at least for using with MinGW).
On my system I found that C:\Perl\Site\Bin was not in my PATH, only C:\Perl\Bin was... Once I updated that the perl -V:xxx commands gave the correct results,
make='dmake'; and
cc='gcc'; respectively.
Then, you should be able to follow the standard Mantra:
perl Makefile.pl
dmake
dmake test
dmake install
During my troubles, I found that -n switch on dmake quite helpful for troubleshooting, as it shows you what dmake is about to do, without actually doing it. And also the -v switch for verbose error logging.
Would anyone be kind enough to explain why MinGW compiles a fully portable dll and Visual Studio doesn't? Is it just Microsoft trying to dominate everything with their "you must use all our products. And anyway our stuff is incompatible with everyone else - and we like it that way..." kind of approach? Or is it a new industry standard for software development?
And finally, Thanks to everyone for their responses and feedback.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.