1 If you read this file _as_is_, just ignore the funny characters you
2 see. It is written in the POD format (see pod/perlpod.pod) which is
3 specially designed to be readable as is.
7 perlwin32 - Perl under Win32
11 These are instructions for building Perl under Windows (9x, NT and
16 Before you start, you should glance through the README file
17 found in the top-level directory where the Perl distribution
18 was extracted. Make sure you read and understand the terms under
19 which this software is being distributed.
21 Also make sure you read L<BUGS AND CAVEATS> below for the
22 known limitations of this port.
24 The INSTALL file in the perl top-level has much information that is
25 only relevant to people building Perl on Unix-like systems. In
26 particular, you can safely ignore any information that talks about
29 You may also want to look at two other options for building
30 a perl that will work on Windows NT: the README.cygwin and
31 README.os2 files, which each give a different set of rules to build
32 a Perl that will work on Win32 platforms. Those two methods will
33 probably enable you to build a more Unix-compatible perl, but you
34 will also need to download and use various other build-time and
35 run-time support software described in those files.
37 This set of instructions is meant to describe a so-called "native"
38 port of Perl to Win32 platforms. The resulting Perl requires no
39 additional software to run (other than what came with your operating
40 system). Currently, this port is capable of using one of the
43 Borland C++ version 5.02 or later
44 Microsoft Visual C++ version 4.2 or later
45 Mingw32 with GCC version 2.95.2 or better
47 The last of these is a high quality freeware compiler. Support
48 for it is still experimental. (Older versions of GCC are known
51 This port currently supports MakeMaker (the set of modules that
52 is used to build extensions to perl). Therefore, you should be
53 able to build and install most extensions found in the CPAN sites.
54 See L<Usage Hints> below for general hints about this.
62 You need a "make" program to build the sources. If you are using
63 Visual C++ under Windows NT or 2000, nmake will work. All other
66 dmake is a freely available make that has very nice macro features
69 A port of dmake for Windows is available from:
71 http://www.cpan.org/authors/id/GSAR/dmake-4.1pl1-win32.zip
73 (This is a fixed version of original dmake sources obtained from
74 http://www.wticorp.com/dmake/. As of version 4.1PL1, the original
75 sources did not build as shipped, and had various other problems.
76 A patch is included in the above fixed version.)
78 Fetch and install dmake somewhere on your path (follow the instructions
79 in the README.NOW file).
83 Use the default "cmd" shell that comes with NT. Some versions of the
84 popular 4DOS/NT shell have incompatibilities that may cause you trouble.
85 If the build fails under that shell, try building again with the cmd
88 The nmake Makefile also has known incompatibilites with the
89 "command.com" shell that comes with Windows 9x. You will need to
90 use dmake and makefile.mk to build under Windows 9x.
92 The surest way to build it is on Windows NT, using the cmd shell.
94 Make sure the path to the build directory does not contain spaces. The
95 build usually works in this circumstance, but some tests will fail.
99 If you are using the Borland compiler, you will need dmake.
100 (The make that Borland supplies is seriously crippled, and will not
101 work for MakeMaker builds.)
105 =item Microsoft Visual C++
107 The nmake that comes with Visual C++ will suffice for building.
108 You will need to run the VCVARS32.BAT file usually found somewhere
109 like C:\MSDEV4.2\BIN. This will set your build environment.
111 You can also use dmake to build using Visual C++, provided:
112 you set OSRELEASE to "microsft" (or whatever the directory name
113 under which the Visual C dmake configuration lives) in your environment,
114 and edit win32/config.vc to change "make=nmake" into "make=dmake". The
115 latter step is only essential if you want to use dmake as your default
116 make for building extensions using MakeMaker.
118 =item Mingw32 with GCC
120 GCC-2.95.2 binaries can be downloaded from:
122 ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/
124 The GCC-2.95.2 bundle comes with Mingw32 libraries and headers.
126 Make sure you install the binaries that work with MSVCRT.DLL as indicated
127 in the README for the GCC bundle. You may need to set up a few environment
128 variables (usually run from a batch file).
130 You also need dmake. See L</"Make"> above on how to get it.
140 Make sure you are in the "win32" subdirectory under the perl toplevel.
141 This directory contains a "Makefile" that will work with
142 versions of nmake that come with Visual C++, and a dmake "makefile.mk"
143 that will work for all supported compilers. The defaults in the dmake
144 makefile are setup to build using the GCC compiler.
148 Edit the makefile.mk (or Makefile, if using nmake) and change the values
149 of INST_DRV and INST_TOP. You can also enable various build
150 flags. These are explained in the makefiles.
152 You will have to make sure CCTYPE is set correctly, and CCHOME points
153 to wherever you installed your compiler.
155 The default value for CCHOME in the makefiles for Visual C++
156 may not be correct for some versions. Make sure the default exists
159 If you have either the source or a library that contains des_fcrypt(),
160 enable the appropriate option in the makefile. des_fcrypt() is not
161 bundled with the distribution due to US Government restrictions
162 on the export of cryptographic software. Nevertheless, this routine
163 is part of the "libdes" library (written by Eric Young) which is widely
164 available worldwide, usually along with SSLeay (for example:
165 "ftp://fractal.mta.ca/pub/crypto/SSLeay/DES/"). Set CRYPT_SRC to the
166 name of the file that implements des_fcrypt(). Alternatively, if
167 you have built a library that contains des_fcrypt(), you can set
168 CRYPT_LIB to point to the library name. The location above contains
169 many versions of the "libdes" library, all with slightly different
170 implementations of des_fcrypt(). Older versions have a single,
171 self-contained file (fcrypt.c) that implements crypt(), so they may be
172 easier to use. A patch against the fcrypt.c found in libdes-3.06 is
175 Perl will also build without des_fcrypt(), but the crypt() builtin will
178 Be sure to read the instructions near the top of the makefiles carefully.
182 Type "dmake" (or "nmake" if you are using that make).
184 This should build everything. Specifically, it will create perl.exe,
185 perl56.dll at the perl toplevel, and various other extension dll's
186 under the lib\auto directory. If the build fails for any reason, make
187 sure you have done the previous steps correctly.
193 Type "dmake test" (or "nmake test"). This will run most of the tests from
194 the testsuite (many tests will be skipped, but no tests should typically
197 If some tests do fail, it may be because you are using a different command
198 shell than the native "cmd.exe", or because you are building from a path
199 that contains spaces. So don't do that.
201 If you are running the tests from a emacs shell window, you may see
202 failures in op/stat.t. Run "dmake test-notty" in that case.
204 If you're using the Borland compiler, you may see a failure in op/taint.t
205 arising from the inability to find the Borland Runtime DLLs on the system
206 default path. You will need to copy the DLLs reported by the messages
207 from where Borland chose to install it, into the Windows system directory
208 (usually somewhere like C:\WINNT\SYSTEM32), and rerun the test.
210 Please report any other failures as described under L<BUGS AND CAVEATS>.
214 Type "dmake install" (or "nmake install"). This will put the newly
215 built perl and the libraries under whatever C<INST_TOP> points to in the
216 Makefile. It will also install the pod documentation under
217 C<$INST_TOP\$VERSION\lib\pod> and HTML versions of the same under
218 C<$INST_TOP\$VERSION\lib\pod\html>. To use the Perl you just installed,
219 you will need to add two components to your PATH environment variable,
220 C<$INST_TOP\$VERSION\bin>, and C<$INST_TOP\$VERSION\bin\$ARCHNAME>.
223 set PATH c:\perl\5.6.0\bin;c:\perl\5.6.0\bin\MSWin32-x86;%PATH%
225 If you opt to comment out INST_VER and INST_ARCH in the makefiles, the
226 installation structure is much simpler. In that case, it will be
227 sufficient to add a single entry to the path, for instance:
229 set PATH c:\perl\bin;%PATH%
235 =item Environment Variables
237 The installation paths that you set during the build get compiled
238 into perl, so you don't have to do anything additional to start
239 using that perl (except add its location to your PATH variable).
241 If you put extensions in unusual places, you can set PERL5LIB
242 to a list of paths separated by semicolons where you want perl
243 to look for libraries. Look for descriptions of other environment
244 variables you can set in L<perlrun>.
246 You can also control the shell that perl uses to run system() and
247 backtick commands via PERL5SHELL. See L<perlrun>.
249 Perl does not depend on the registry, but it can look up certain default
250 values if you choose to put them there. Perl attempts to read entries from
251 C<HKEY_CURRENT_USER\Software\Perl> and C<HKEY_LOCAL_MACHINE\Software\Perl>.
252 Entries in the former override entries in the latter. One or more of the
253 following entries (of type REG_SZ or REG_EXPAND_SZ) may be set:
255 lib-$] version-specific standard library path to add to @INC
256 lib standard library path to add to @INC
257 sitelib-$] version-specific site library path to add to @INC
258 sitelib site library path to add to @INC
259 vendorlib-$] version-specific vendor library path to add to @INC
260 vendorlib vendor library path to add to @INC
261 PERL* fallback for all %ENV lookups that begin with "PERL"
263 Note the C<$]> in the above is not literal. Substitute whatever version
264 of perl you want to honor that entry, e.g. C<5.6.0>. Paths must be
265 separated with semicolons, as usual on win32.
269 By default, perl handles file globbing using the File::Glob extension,
270 which provides portable globbing.
272 If you want perl to use globbing that emulates the quirks of DOS
273 filename conventions, you might want to consider using File::DosGlob
274 to override the internal glob() implementation. See L<File::DosGlob> for
277 =item Using perl from the command line
279 If you are accustomed to using perl from various command-line
280 shells found in UNIX environments, you will be less than pleased
281 with what Windows offers by way of a command shell.
283 The crucial thing to understand about the "cmd" shell (which is
284 the default on Windows NT) is that it does not do any wildcard
285 expansions of command-line arguments (so wildcards need not be
286 quoted). It also provides only rudimentary quoting. The only
287 (useful) quote character is the double quote ("). It can be used to
288 protect spaces in arguments and other special characters. The
289 Windows NT documentation has almost no description of how the
290 quoting rules are implemented, but here are some general observations
291 based on experiments: The shell breaks arguments at spaces and
292 passes them to programs in argc/argv. Doublequotes can be used
293 to prevent arguments with spaces in them from being split up.
294 You can put a double quote in an argument by escaping it with
295 a backslash and enclosing the whole argument within double quotes.
296 The backslash and the pair of double quotes surrounding the
297 argument will be stripped by the shell.
299 The file redirection characters "<", ">", and "|" cannot be quoted
300 by double quotes (there are probably more such). Single quotes
301 will protect those three file redirection characters, but the
302 single quotes don't get stripped by the shell (just to make this
303 type of quoting completely useless). The caret "^" has also
304 been observed to behave as a quoting character (and doesn't get
305 stripped by the shell also).
307 Here are some examples of usage of the "cmd" shell:
309 This prints two doublequotes:
311 perl -e "print '\"\"' "
315 perl -e "print \"\\\"\\\"\" "
317 This prints "bar" and writes "foo" to the file "blurch":
319 perl -e "print 'foo'; print STDERR 'bar'" > blurch
321 This prints "foo" ("bar" disappears into nowhereland):
323 perl -e "print 'foo'; print STDERR 'bar'" 2> nul
325 This prints "bar" and writes "foo" into the file "blurch":
327 perl -e "print 'foo'; print STDERR 'bar'" 1> blurch
329 This pipes "foo" to the "less" pager and prints "bar" on the console:
331 perl -e "print 'foo'; print STDERR 'bar'" | less
333 This pipes "foo\nbar\n" to the less pager:
335 perl -le "print 'foo'; print STDERR 'bar'" 2>&1 | less
337 This pipes "foo" to the pager and writes "bar" in the file "blurch":
339 perl -e "print 'foo'; print STDERR 'bar'" 2> blurch | less
342 Discovering the usefulness of the "command.com" shell on Windows 9x
343 is left as an exercise to the reader :)
345 =item Building Extensions
347 The Comprehensive Perl Archive Network (CPAN) offers a wealth
348 of extensions, some of which require a C compiler to build.
349 Look in http://www.cpan.org/ for more information on CPAN.
351 Note that not all of the extensions available from CPAN may work
352 in the Win32 environment; you should check the information at
353 http://testers.cpan.org/ before investing too much effort into
354 porting modules that don't readily build.
356 Most extensions (whether they require a C compiler or not) can
357 be built, tested and installed with the standard mantra:
364 where $MAKE is whatever 'make' program you have configured perl to
365 use. Use "perl -V:make" to find out what this is. Some extensions
366 may not provide a testsuite (so "$MAKE test" may not do anything, or
367 fail), but most serious ones do.
369 It is important that you use a supported 'make' program, and
370 ensure Config.pm knows about it. If you don't have nmake, you can
371 either get dmake from the location mentioned earlier, or get an
372 old version of nmake reportedly available from:
374 ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe
376 Another option is to use the make written in Perl, available from
379 http://www.cpan.org/authors/id/NI-S/Make-0.03.tar.gz
381 You may also use dmake. See L</"Make"> above on how to get it.
383 Note that MakeMaker actually emits makefiles with different syntax
384 depending on what 'make' it thinks you are using. Therefore, it is
385 important that one of the following values appears in Config.pm:
387 make='nmake' # MakeMaker emits nmake syntax
388 make='dmake' # MakeMaker emits dmake syntax
389 any other value # MakeMaker emits generic make syntax
390 (e.g GNU make, or Perl make)
392 If the value doesn't match the 'make' program you want to use,
393 edit Config.pm to fix it.
395 If a module implements XSUBs, you will need one of the supported
396 C compilers. You must make sure you have set up the environment for
397 the compiler for command-line compilation.
399 If a module does not build for some reason, look carefully for
400 why it failed, and report problems to the module author. If
401 it looks like the extension building support is at fault, report
402 that with full details of how the build failed using the perlbug
405 =item Command-line Wildcard Expansion
407 The default command shells on DOS descendant operating systems (such
408 as they are) usually do not expand wildcard arguments supplied to
409 programs. They consider it the application's job to handle that.
410 This is commonly achieved by linking the application (in our case,
411 perl) with startup code that the C runtime libraries usually provide.
412 However, doing that results in incompatible perl versions (since the
413 behavior of the argv expansion code differs depending on the
414 compiler, and it is even buggy on some compilers). Besides, it may
415 be a source of frustration if you use such a perl binary with an
416 alternate shell that *does* expand wildcards.
418 Instead, the following solution works rather well. The nice things
419 about it: 1) you can start using it right away 2) it is more powerful,
420 because it will do the right thing with a pattern like */*/*.c
421 3) you can decide whether you do/don't want to use it 4) you can
422 extend the method to add any customizations (or even entirely
423 different kinds of wildcard expansion).
425 C:\> copy con c:\perl\lib\Wild.pm
426 # Wild.pm - emulate shell @ARGV expansion on shells that don't
429 my @g = File::DosGlob::glob($_) if /[*?]/;
434 C:\> set PERL5OPT=-MWild
435 C:\> perl -le "for (@ARGV) { print }" */*/perl*.c
439 perl5.005/win32/perlglob.c
440 perl5.005/win32/perllib.c
441 perl5.005/win32/perlglob.c
442 perl5.005/win32/perllib.c
443 perl5.005/win32/perlglob.c
444 perl5.005/win32/perllib.c
446 Note there are two distinct steps there: 1) You'll have to create
447 Wild.pm and put it in your perl lib directory. 2) You'll need to
448 set the PERL5OPT environment variable. If you want argv expansion
449 to be the default, just set PERL5OPT in your default startup
452 If you are using the Visual C compiler, you can get the C runtime's
453 command line wildcard expansion built into perl binary. The resulting
454 binary will always expand unquoted command lines, which may not be
455 what you want if you use a shell that does that for you. The expansion
456 done is also somewhat less powerful than the approach suggested above.
458 =item Win32 Specific Extensions
460 A number of extensions specific to the Win32 platform are available
461 from CPAN. You may find that many of these extensions are meant to
462 be used under the Activeware port of Perl, which used to be the only
463 native port for the Win32 platform. Since the Activeware port does not
464 have adequate support for Perl's extension building tools, these
465 extensions typically do not support those tools either, and therefore
466 cannot be built using the generic steps shown in the previous section.
468 To ensure smooth transitioning of existing code that uses the
469 ActiveState port, there is a bundle of Win32 extensions that contains
470 all of the ActiveState extensions and most other Win32 extensions from
471 CPAN in source form, along with many added bugfixes, and with MakeMaker
472 support. This bundle is available at:
474 http://www.cpan.org/authors/id/GSAR/libwin32-0.151.zip
476 See the README in that distribution for building and installation
477 instructions. Look for later versions that may be available at the
480 =item Running Perl Scripts
482 Perl scripts on UNIX use the "#!" (a.k.a "shebang") line to
483 indicate to the OS that it should execute the file using perl.
484 Win32 has no comparable means to indicate arbitrary files are
487 Instead, all available methods to execute plain text files on
488 Win32 rely on the file "extension". There are three methods
489 to use this to execute perl scripts:
495 There is a facility called "file extension associations" that will
496 work in Windows NT 4.0. This can be manipulated via the two
497 commands "assoc" and "ftype" that come standard with Windows NT
498 4.0. Type "ftype /?" for a complete example of how to set this
499 up for perl scripts (Say what? You thought Windows NT wasn't
504 Since file associations don't work everywhere, and there are
505 reportedly bugs with file associations where it does work, the
506 old method of wrapping the perl script to make it look like a
507 regular batch file to the OS, may be used. The install process
508 makes available the "pl2bat.bat" script which can be used to wrap
509 perl scripts into batch files. For example:
513 will create the file "FOO.BAT". Note "pl2bat" strips any
514 .pl suffix and adds a .bat suffix to the generated file.
516 If you use the 4DOS/NT or similar command shell, note that
517 "pl2bat" uses the "%*" variable in the generated batch file to
518 refer to all the command line arguments, so you may need to make
519 sure that construct works in batch files. As of this writing,
520 4DOS/NT users will need a "ParameterChar = *" statement in their
521 4NT.INI file, or will need to execute "setdos /p*" in the 4DOS/NT
522 startup file to enable this to work.
526 Using "pl2bat" has a few problems: the file name gets changed,
527 so scripts that rely on C<$0> to find what they must do may not
528 run properly; running "pl2bat" replicates the contents of the
529 original script, and so this process can be maintenance intensive
530 if the originals get updated often. A different approach that
531 avoids both problems is possible.
533 A script called "runperl.bat" is available that can be copied
534 to any filename (along with the .bat suffix). For example,
535 if you call it "foo.bat", it will run the file "foo" when it is
536 executed. Since you can run batch files on Win32 platforms simply
537 by typing the name (without the extension), this effectively
538 runs the file "foo", when you type either "foo" or "foo.bat".
539 With this method, "foo.bat" can even be in a different location
540 than the file "foo", as long as "foo" is available somewhere on
541 the PATH. If your scripts are on a filesystem that allows symbolic
542 links, you can even avoid copying "runperl.bat".
544 Here's a diversion: copy "runperl.bat" to "runperl", and type
545 "runperl". Explain the observed behavior, or lack thereof. :)
546 Hint: .gnidnats llits er'uoy fi ,"lrepnur" eteled :tniH
550 =item Miscellaneous Things
552 A full set of HTML documentation is installed, so you should be
553 able to use it if you have a web browser installed on your
556 C<perldoc> is also a useful tool for browsing information contained
557 in the documentation, especially in conjunction with a pager
558 like C<less> (recent versions of which have Win32 support). You may
559 have to set the PAGER environment variable to use a specific pager.
560 "perldoc -f foo" will print information about the perl operator
563 If you find bugs in perl, you can run C<perlbug> to create a
564 bug report (you may have to send it manually if C<perlbug> cannot
565 find a mailer on your system).
569 =head1 BUGS AND CAVEATS
571 Some of the built-in functions do not act exactly as documented in
572 L<perlfunc>, and a few are not implemented at all. To avoid
573 surprises, particularly if you have had prior exposure to Perl
574 in other operating environments or if you intend to write code
575 that will be portable to other environments, see L<perlport>
576 for a reasonably definitive list of these differences.
578 Not all extensions available from CPAN may build or work properly
579 in the Win32 environment. See L</"Building Extensions">.
581 Most C<socket()> related calls are supported, but they may not
582 behave as on Unix platforms. See L<perlport> for the full list.
584 Signal handling may not behave as on Unix platforms (where it
585 doesn't exactly "behave", either :). For instance, calling C<die()>
586 or C<exit()> from signal handlers will cause an exception, since most
587 implementations of C<signal()> on Win32 are severely crippled.
588 Thus, signals may work only for simple things like setting a flag
589 variable in the handler. Using signals under this port should
590 currently be considered unsupported.
592 Please send detailed descriptions of any problems and solutions that
593 you may find to <F<perlbug@perl.com>>, along with the output produced
600 Gary Ng E<lt>71564.1743@CompuServe.COME<gt>
602 Gurusamy Sarathy E<lt>gsar@activestate.comE<gt>
604 Nick Ing-Simmons E<lt>nick@ni-s.u-net.comE<gt>
608 This document is maintained by Gurusamy Sarathy.
616 This port was originally contributed by Gary Ng around 5.003_24,
617 and borrowed from the Hip Communications port that was available
618 at the time. Various people have made numerous and sundry hacks
621 Borland support was added in 5.004_01 (Gurusamy Sarathy).
623 GCC/mingw32 support was added in 5.005 (Nick Ing-Simmons).
625 Support for PERL_OBJECT was added in 5.005 (ActiveState Tool Corp).
627 Support for fork() emulation was added in 5.6 (ActiveState Tool Corp).
629 Win9x support was added in 5.6 (Benjamin Stuhl).
631 Last updated: 13 March 2000