1PERLWIN32(1) Perl Programmers Reference Guide PERLWIN32(1)
2
3
4
6 perlwin32 - Perl under Windows
7
9 These are instructions for building Perl under Windows 2000 and later.
10
12 Before you start, you should glance through the README file found in
13 the top-level directory to which the Perl distribution was extracted.
14 Make sure you read and understand the terms under which this software
15 is being distributed.
16
17 Also make sure you read "BUGS AND CAVEATS" below for the known
18 limitations of this port.
19
20 The INSTALL file in the perl top-level has much information that is
21 only relevant to people building Perl on Unix-like systems. In
22 particular, you can safely ignore any information that talks about
23 "Configure".
24
25 You may also want to look at one other option for building a perl that
26 will work on Windows: the README.cygwin file, which give a different
27 set of rules to build a perl for Windows. This method will probably
28 enable you to build a more Unix-compatible perl, but you will also need
29 to download and use various other build-time and run-time support
30 software described in that file.
31
32 This set of instructions is meant to describe a so-called "native" port
33 of Perl to the Windows platform. This includes both 32-bit and 64-bit
34 Windows operating systems. The resulting Perl requires no additional
35 software to run (other than what came with your operating system).
36 Currently, this port is capable of using one of the following compilers
37 on the Intel x86 architecture:
38
39 Microsoft Visual C++ version 6.0 or later
40 Intel C++ Compiler (experimental)
41 Gcc by mingw.org gcc version 3.4.5 or later
42 Gcc by mingw-w64.org gcc version 4.4.3 or later
43
44 Note that the last two of these are actually competing projects both
45 delivering complete gcc toolchain for MS Windows:
46
47 <http://mingw.org>
48 Delivers gcc toolchain targeting 32-bit Windows platform.
49
50 <http://mingw-w64.org>
51 Delivers gcc toolchain targeting both 64-bit Windows and 32-bit
52 Windows platforms (despite the project name "mingw-w64" they are
53 not only 64-bit oriented). They deliver the native gcc compilers
54 and cross-compilers that are also supported by perl's makefile.
55
56 The Microsoft Visual C++ compilers are also now being given away free.
57 They are available as "Visual C++ Toolkit 2003" or "Visual C++
58 2005-2017 Express [or Community, from 2017] Edition" (and also as part
59 of the ".NET Framework SDK") and are the same compilers that ship with
60 "Visual C++ .NET 2003 Professional" or "Visual C++ 2005-2017
61 Professional" respectively.
62
63 This port can also be built on IA64/AMD64 using:
64
65 Microsoft Platform SDK Nov 2001 (64-bit compiler and tools)
66 MinGW64 compiler (gcc version 4.4.3 or later)
67
68 The Windows SDK can be downloaded from <http://www.microsoft.com/>.
69 The MinGW64 compiler is available at <http://mingw-w64.org>. The
70 latter is actually a cross-compiler targeting Win64. There's also a
71 trimmed down compiler (no java, or gfortran) suitable for building perl
72 available at: <http://strawberryperl.com/package/kmx/64_gcctoolchain/>
73
74 NOTE: If you're using a 32-bit compiler to build perl on a 64-bit
75 Windows operating system, then you should set the WIN64 environment
76 variable to "undef". Also, the trimmed down compiler only passes tests
77 when USE_ITHREADS *= define (as opposed to undef) and when the CFG *=
78 Debug line is commented out.
79
80 This port fully supports MakeMaker (the set of modules that is used to
81 build extensions to perl). Therefore, you should be able to build and
82 install most extensions found in the CPAN sites. See "Usage Hints for
83 Perl on Windows" below for general hints about this.
84
85 Setting Up Perl on Windows
86 Make
87 You need a "make" program to build the sources. If you are using
88 Visual C++ or the Windows SDK tools, you can use nmake supplied
89 with Visual C++ or Windows SDK. You may also use, for Visual C++ or
90 Windows SDK, dmake or gmake instead of nmake. dmake is open source
91 software, but is not included with Visual C++ or Windows SDK.
92 Builds using gcc need dmake or gmake. nmake is not supported for
93 gcc builds. Parallel building is only supported with dmake and
94 gmake, not nmake. When using dmake it is recommended to use dmake
95 4.13 or newer for parallel building. Older dmakes, in parallel
96 mode, have very high CPU usage and pound the disk/filing system
97 with duplicate I/O calls in an aggressive polling loop.
98
99 A port of dmake for Windows is available from:
100
101 <http://search.cpan.org/dist/dmake/>
102
103 Fetch and install dmake somewhere on your path.
104
105 Command Shell
106 Use the default "cmd" shell that comes with Windows. Some versions
107 of the popular 4DOS/NT shell have incompatibilities that may cause
108 you trouble. If the build fails under that shell, try building
109 again with the cmd shell.
110
111 Make sure the path to the build directory does not contain spaces.
112 The build usually works in this circumstance, but some tests will
113 fail.
114
115 Microsoft Visual C++
116 The nmake that comes with Visual C++ will suffice for building.
117 Visual C requires that certain things be set up in the console
118 before Visual C will sucessfully run. To make a console box be able
119 to run the C compiler, you will need to beforehand, run the
120 "vcvars32.bat" file to compile for x86-32 and for x86-64
121 "vcvarsall.bat x64" or "vcvarsamd64.bat". On a typical install of a
122 Microsoft C compiler product, these batch files will already be in
123 your "PATH" environment variable so you may just type them without
124 an absolute path into your console. If you need to find the
125 absolute path to the batch file, it is usually found somewhere like
126 C:\Program Files\Microsoft Visual Studio\VC98\Bin. With some newer
127 Micrsoft C products (released after ~2004), the installer will put
128 a shortcut in the start menu to launch a new console window with
129 the console already set up for your target architecture (x86-32 or
130 x86-64 or IA64). With the newer compilers, you may also use the
131 older batch files if you choose so.
132
133 Microsoft Visual C++ 2008-2017 Express/Community Edition
134 These free versions of Visual C++ 2008-2017 Professional contain
135 the same compilers and linkers that ship with the full versions,
136 and also contain everything necessary to build Perl, rather than
137 requiring a separate download of the Windows SDK like previous
138 versions did.
139
140 These packages can be downloaded by searching in the Download
141 Center at
142 <http://www.microsoft.com/downloads/search.aspx?displaylang=en>.
143 (Providing exact links to these packages has proven a pointless
144 task because the links keep on changing so often.)
145
146 Install Visual C++ 2008-2017 Express/Community, then setup your
147 environment using, e.g.
148
149 C:\Program Files\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat
150
151 (assuming the default installation location was chosen).
152
153 Perl should now build using the win32/Makefile. You will need to
154 edit that file to set CCTYPE to one of MSVC90FREE-MSVC141FREE
155 first.
156
157 Microsoft Visual C++ 2005 Express Edition
158 This free version of Visual C++ 2005 Professional contains the same
159 compiler and linker that ship with the full version, but doesn't
160 contain everything necessary to build Perl.
161
162 You will also need to download the "Windows SDK" (the "Core SDK"
163 and "MDAC SDK" components are required) for more header files and
164 libraries.
165
166 These packages can both be downloaded by searching in the Download
167 Center at
168 <http://www.microsoft.com/downloads/search.aspx?displaylang=en>.
169 (Providing exact links to these packages has proven a pointless
170 task because the links keep on changing so often.)
171
172 Try to obtain the latest version of the Windows SDK. Sometimes
173 these packages contain a particular Windows OS version in their
174 name, but actually work on other OS versions too. For example, the
175 "Windows Server 2003 R2 Platform SDK" also runs on Windows XP SP2
176 and Windows 2000.
177
178 Install Visual C++ 2005 first, then the Platform SDK. Setup your
179 environment as follows (assuming default installation locations
180 were chosen):
181
182 SET PlatformSDKDir=C:\Program Files\Microsoft Platform SDK
183
184 SET PATH=%SystemRoot%\system32;%SystemRoot%;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;%PlatformSDKDir%\Bin
185
186 SET INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;%PlatformSDKDir%\include
187
188 SET LIB=C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%PlatformSDKDir%\lib
189
190 SET LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
191
192 (The PlatformSDKDir might need to be set differently depending on
193 which version you are using. Earlier versions installed into
194 "C:\Program Files\Microsoft SDK", while the latest versions install
195 into version-specific locations such as "C:\Program Files\Microsoft
196 Platform SDK for Windows Server 2003 R2".)
197
198 Perl should now build using the win32/Makefile. You will need to
199 edit that file to set
200
201 CCTYPE = MSVC80FREE
202
203 and to set CCHOME, CCINCDIR and CCLIBDIR as per the environment
204 setup above.
205
206 Microsoft Visual C++ Toolkit 2003
207 This free toolkit contains the same compiler and linker that ship
208 with Visual C++ .NET 2003 Professional, but doesn't contain
209 everything necessary to build Perl.
210
211 You will also need to download the "Platform SDK" (the "Core SDK"
212 and "MDAC SDK" components are required) for header files, libraries
213 and rc.exe, and ".NET Framework SDK" for more libraries and
214 nmake.exe. Note that the latter (which also includes the free
215 compiler and linker) requires the ".NET Framework Redistributable"
216 to be installed first. This can be downloaded and installed
217 separately, but is included in the "Visual C++ Toolkit 2003"
218 anyway.
219
220 These packages can all be downloaded by searching in the Download
221 Center at
222 <http://www.microsoft.com/downloads/search.aspx?displaylang=en>.
223 (Providing exact links to these packages has proven a pointless
224 task because the links keep on changing so often.)
225
226 Try to obtain the latest version of the Windows SDK. Sometimes
227 these packages contain a particular Windows OS version in their
228 name, but actually work on other OS versions too. For example, the
229 "Windows Server 2003 R2 Platform SDK" also runs on Windows XP SP2
230 and Windows 2000.
231
232 Install the Toolkit first, then the Platform SDK, then the .NET
233 Framework SDK. Setup your environment as follows (assuming default
234 installation locations were chosen):
235
236 SET PlatformSDKDir=C:\Program Files\Microsoft Platform SDK
237
238 SET PATH=%SystemRoot%\system32;%SystemRoot%;C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;%PlatformSDKDir%\Bin;C:\Program Files\Microsoft.NET\SDK\v1.1\Bin
239
240 SET INCLUDE=C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%PlatformSDKDir%\include;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
241
242 SET LIB=C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%PlatformSDKDir%\lib;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib
243
244 (The PlatformSDKDir might need to be set differently depending on
245 which version you are using. Earlier versions installed into
246 "C:\Program Files\Microsoft SDK", while the latest versions install
247 into version-specific locations such as "C:\Program Files\Microsoft
248 Platform SDK for Windows Server 2003 R2".)
249
250 Several required files will still be missing:
251
252 · cvtres.exe is required by link.exe when using a .res file. It
253 is actually installed by the .NET Framework SDK, but into a
254 location such as the following:
255
256 C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
257
258 Copy it from there to %PlatformSDKDir%\Bin
259
260 · lib.exe is normally used to build libraries, but link.exe with
261 the /lib option also works, so change win32/config.vc to use it
262 instead:
263
264 Change the line reading:
265
266 ar='lib'
267
268 to:
269
270 ar='link /lib'
271
272 It may also be useful to create a batch file called lib.bat in
273 C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin
274 containing:
275
276 @echo off
277 link /lib %*
278
279 for the benefit of any naughty C extension modules that you
280 might want to build later which explicitly reference "lib"
281 rather than taking their value from $Config{ar}.
282
283 · setargv.obj is required to build perlglob.exe (and perl.exe if
284 the USE_SETARGV option is enabled). The Platform SDK supplies
285 this object file in source form in %PlatformSDKDir%\src\crt.
286 Copy setargv.c, cruntime.h and internal.h from there to some
287 temporary location and build setargv.obj using
288
289 cl.exe /c /I. /D_CRTBLD setargv.c
290
291 Then copy setargv.obj to %PlatformSDKDir%\lib
292
293 Alternatively, if you don't need perlglob.exe and don't need to
294 enable the USE_SETARGV option then you can safely just remove
295 all mention of $(GLOBEXE) from win32/Makefile and setargv.obj
296 won't be required anyway.
297
298 Perl should now build using the win32/Makefile. You will need to
299 edit that file to set
300
301 CCTYPE = MSVC70FREE
302
303 and to set CCHOME, CCINCDIR and CCLIBDIR as per the environment
304 setup above.
305
306 Microsoft Platform SDK 64-bit Compiler
307 The nmake that comes with the Platform SDK will suffice for
308 building Perl. Make sure you are building within one of the "Build
309 Environment" shells available after you install the Platform SDK
310 from the Start Menu.
311
312 MinGW release 3 with gcc
313 Perl can be compiled with gcc from MinGW release 3 and later (using
314 gcc 3.4.5 and later). It can be downloaded here:
315
316 <http://www.mingw.org/>
317
318 You also need dmake. See "Make" above on how to get it.
319
320 Intel C++ Compiler
321 Experimental support for using Intel C++ Compiler has been added.
322 Edit win32/Makefile and pick the correct CCTYPE for the Visual C
323 that Intel C was installed into. Also uncomment __ICC to enable
324 Intel C on Visual C support. To set up the build enviroment, from
325 the Start Menu run IA-32 Visual Studio 20__ mode or Intel 64 Visual
326 Studio 20__ mode as appropriate. Then run nmake as usually in that
327 prompt box.
328
329 Only Intel C++ Compiler v12.1 has been tested. Other versions
330 probably will work. Using Intel C++ Compiler instead of Visual C
331 has the benefit of C99 compatibility which is needed by some CPAN
332 XS modules, while maintaining compatibility with Visual C object
333 code and Visual C debugging infrastructure unlike GCC.
334
335 Building
336 · Make sure you are in the "win32" subdirectory under the perl
337 toplevel. This directory contains a "Makefile" that will work with
338 versions of nmake that come with Visual C++ or the Windows SDK, and
339 a dmake "makefile.mk" that will work for all supported compilers.
340 The defaults in the dmake makefile are setup to build using
341 MinGW/gcc.
342
343 · Edit the makefile.mk (or Makefile, if you're using nmake) and
344 change the values of INST_DRV and INST_TOP. You can also enable
345 various build flags. These are explained in the makefiles.
346
347 Note that it is generally not a good idea to try to build a perl
348 with INST_DRV and INST_TOP set to a path that already exists from a
349 previous build. In particular, this may cause problems with the
350 lib/ExtUtils/t/Embed.t test, which attempts to build a test program
351 and may end up building against the installed perl's lib/CORE
352 directory rather than the one being tested.
353
354 You will have to make sure that CCTYPE is set correctly and that
355 CCHOME points to wherever you installed your compiler.
356
357 If building with the cross-compiler provided by mingw-w64.org
358 you'll need to uncomment the line that sets GCCCROSS in the
359 makefile.mk. Do this only if it's the cross-compiler - ie only if
360 the bin folder doesn't contain a gcc.exe. (The cross-compiler does
361 not provide a gcc.exe, g++.exe, ar.exe, etc. Instead, all of these
362 executables are prefixed with 'x86_64-w64-mingw32-'.)
363
364 The default value for CCHOME in the makefiles for Visual C++ may
365 not be correct for some versions. Make sure the default exists and
366 is valid.
367
368 You may also need to comment out the "DELAYLOAD = ..." line in the
369 Makefile if you're using VC++ 6.0 without the latest service pack
370 and the linker reports an internal error.
371
372 If you want build some core extensions statically into perl's dll,
373 specify them in the STATIC_EXT macro.
374
375 NOTE: The USE_64_BIT_INT build option is not supported with the
376 32-bit Visual C++ 6.0 compiler.
377
378 Be sure to read the instructions near the top of the makefiles
379 carefully.
380
381 · Type "dmake" (or "nmake" if you are using that make).
382
383 This should build everything. Specifically, it will create
384 perl.exe, perl526.dll at the perl toplevel, and various other
385 extension dll's under the lib\auto directory. If the build fails
386 for any reason, make sure you have done the previous steps
387 correctly.
388
389 To try dmake's parallel mode, type "dmake -P2", where 2, is the
390 maximum number of parallel jobs you want to run. A number of things
391 in the build process will run in parallel, but there are
392 serialization points where you will see just 1 CPU maxed out. This
393 is normal.
394
395 If you are advanced enough with building C code, here is a
396 suggestion to speed up building perl, and the later "make test".
397 Try to keep your PATH enviromental variable with the least number
398 of folders possible (remember to keep your C compiler's folders
399 there). "C:\WINDOWS\system32" or "C:\WINNT\system32" depending on
400 your OS version should be first folder in PATH, since "cmd.exe" is
401 the most commonly launched program during the build and later
402 testing.
403
404 Testing Perl on Windows
405 Type "dmake test" (or "nmake test"). This will run most of the tests
406 from the testsuite (many tests will be skipped).
407
408 There should be no test failures.
409
410 If you build with Visual C++ 2013 then three tests currently may fail
411 with Daylight Saving Time related problems: t/io/fs.t,
412 cpan/HTTP-Tiny/t/110_mirror.t and lib/File/Copy.t. The failures are
413 caused by bugs in the CRT in VC++ 2013 which are fixed in VC++2015 and
414 later, as explained by Microsoft here:
415 <https://connect.microsoft.com/VisualStudio/feedback/details/811534/utime-sometimes-fails-to-set-the-correct-file-times-in-visual-c-2013>.
416 In the meantime, if you need fixed "stat" and "utime" functions then
417 have a look at the CPAN distribution Win32::UTCFileTime.
418
419 If you build with certain versions (e.g. 4.8.1) of gcc from
420 www.mingw.org then ext/POSIX/t/time.t may fail test 17 due to a known
421 bug in those gcc builds: see
422 <http://sourceforge.net/p/mingw/bugs/2152/>.
423
424 Some test failures may occur if you use a command shell other than the
425 native "cmd.exe", or if you are building from a path that contains
426 spaces. So don't do that.
427
428 If you are running the tests from a emacs shell window, you may see
429 failures in op/stat.t. Run "dmake test-notty" in that case.
430
431 Furthermore, you should make sure that during "make test" you do not
432 have any GNU tool packages in your path: some toolkits like Unixutils
433 include some tools ("type" for instance) which override the Windows
434 ones and makes tests fail. Remove them from your path while testing to
435 avoid these errors.
436
437 Please report any other failures as described under "BUGS AND CAVEATS".
438
439 Installation of Perl on Windows
440 Type "dmake install" (or "nmake install"). This will put the newly
441 built perl and the libraries under whatever "INST_TOP" points to in the
442 Makefile. It will also install the pod documentation under
443 "$INST_TOP\$INST_VER\lib\pod" and HTML versions of the same under
444 "$INST_TOP\$INST_VER\lib\pod\html".
445
446 To use the Perl you just installed you will need to add a new entry to
447 your PATH environment variable: "$INST_TOP\bin", e.g.
448
449 set PATH=c:\perl\bin;%PATH%
450
451 If you opted to uncomment "INST_VER" and "INST_ARCH" in the makefile
452 then the installation structure is a little more complicated and you
453 will need to add two new PATH components instead:
454 "$INST_TOP\$INST_VER\bin" and "$INST_TOP\$INST_VER\bin\$ARCHNAME", e.g.
455
456 set PATH=c:\perl\5.6.0\bin;c:\perl\5.6.0\bin\MSWin32-x86;%PATH%
457
458 Usage Hints for Perl on Windows
459 Environment Variables
460 The installation paths that you set during the build get compiled
461 into perl, so you don't have to do anything additional to start
462 using that perl (except add its location to your PATH variable).
463
464 If you put extensions in unusual places, you can set PERL5LIB to a
465 list of paths separated by semicolons where you want perl to look
466 for libraries. Look for descriptions of other environment
467 variables you can set in perlrun.
468
469 You can also control the shell that perl uses to run system() and
470 backtick commands via PERL5SHELL. See perlrun.
471
472 Perl does not depend on the registry, but it can look up certain
473 default values if you choose to put them there unless disabled at
474 build time with USE_NO_REGISTRY. On Perl process start Perl checks
475 if "HKEY_CURRENT_USER\Software\Perl" and
476 "HKEY_LOCAL_MACHINE\Software\Perl" exist. If the keys exists, they
477 will be checked for remainder of the Perl process's run life for
478 certain entries. Entries in "HKEY_CURRENT_USER\Software\Perl"
479 override entries in "HKEY_LOCAL_MACHINE\Software\Perl". One or
480 more of the following entries (of type REG_SZ or REG_EXPAND_SZ) may
481 be set in the keys:
482
483 lib-$] version-specific standard library path to add to @INC
484 lib standard library path to add to @INC
485 sitelib-$] version-specific site library path to add to @INC
486 sitelib site library path to add to @INC
487 vendorlib-$] version-specific vendor library path to add to @INC
488 vendorlib vendor library path to add to @INC
489 PERL* fallback for all %ENV lookups that begin with "PERL"
490
491 Note the $] in the above is not literal. Substitute whatever
492 version of perl you want to honor that entry, e.g. 5.6.0. Paths
493 must be separated with semicolons, as usual on Windows.
494
495 File Globbing
496 By default, perl handles file globbing using the File::Glob
497 extension, which provides portable globbing.
498
499 If you want perl to use globbing that emulates the quirks of DOS
500 filename conventions, you might want to consider using
501 File::DosGlob to override the internal glob() implementation. See
502 File::DosGlob for details.
503
504 Using perl from the command line
505 If you are accustomed to using perl from various command-line
506 shells found in UNIX environments, you will be less than pleased
507 with what Windows offers by way of a command shell.
508
509 The crucial thing to understand about the Windows environment is
510 that the command line you type in is processed twice before Perl
511 sees it. First, your command shell (usually CMD.EXE) preprocesses
512 the command line, to handle redirection, environment variable
513 expansion, and location of the executable to run. Then, the perl
514 executable splits the remaining command line into individual
515 arguments, using the C runtime library upon which Perl was built.
516
517 It is particularly important to note that neither the shell nor the
518 C runtime do any wildcard expansions of command-line arguments (so
519 wildcards need not be quoted). Also, the quoting behaviours of the
520 shell and the C runtime are rudimentary at best (and may, if you
521 are using a non-standard shell, be inconsistent). The only
522 (useful) quote character is the double quote ("). It can be used
523 to protect spaces and other special characters in arguments.
524
525 The Windows documentation describes the shell parsing rules here:
526 <http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true>
527 and the C runtime parsing rules here:
528 <http://msdn.microsoft.com/en-us/library/17w5ykft%28v=VS.100%29.aspx>.
529
530 Here are some further observations based on experiments: The C
531 runtime breaks arguments at spaces and passes them to programs in
532 argc/argv. Double quotes can be used to prevent arguments with
533 spaces in them from being split up. You can put a double quote in
534 an argument by escaping it with a backslash and enclosing the whole
535 argument within double quotes. The backslash and the pair of
536 double quotes surrounding the argument will be stripped by the C
537 runtime.
538
539 The file redirection characters "<", ">", and "|" can be quoted by
540 double quotes (although there are suggestions that this may not
541 always be true). Single quotes are not treated as quotes by the
542 shell or the C runtime, they don't get stripped by the shell (just
543 to make this type of quoting completely useless). The caret "^"
544 has also been observed to behave as a quoting character, but this
545 appears to be a shell feature, and the caret is not stripped from
546 the command line, so Perl still sees it (and the C runtime phase
547 does not treat the caret as a quote character).
548
549 Here are some examples of usage of the "cmd" shell:
550
551 This prints two doublequotes:
552
553 perl -e "print '\"\"' "
554
555 This does the same:
556
557 perl -e "print \"\\\"\\\"\" "
558
559 This prints "bar" and writes "foo" to the file "blurch":
560
561 perl -e "print 'foo'; print STDERR 'bar'" > blurch
562
563 This prints "foo" ("bar" disappears into nowhereland):
564
565 perl -e "print 'foo'; print STDERR 'bar'" 2> nul
566
567 This prints "bar" and writes "foo" into the file "blurch":
568
569 perl -e "print 'foo'; print STDERR 'bar'" 1> blurch
570
571 This pipes "foo" to the "less" pager and prints "bar" on the
572 console:
573
574 perl -e "print 'foo'; print STDERR 'bar'" | less
575
576 This pipes "foo\nbar\n" to the less pager:
577
578 perl -le "print 'foo'; print STDERR 'bar'" 2>&1 | less
579
580 This pipes "foo" to the pager and writes "bar" in the file
581 "blurch":
582
583 perl -e "print 'foo'; print STDERR 'bar'" 2> blurch | less
584
585 Discovering the usefulness of the "command.com" shell on Windows 9x
586 is left as an exercise to the reader :)
587
588 One particularly pernicious problem with the 4NT command shell for
589 Windows is that it (nearly) always treats a % character as
590 indicating that environment variable expansion is needed. Under
591 this shell, it is therefore important to always double any %
592 characters which you want Perl to see (for example, for hash
593 variables), even when they are quoted.
594
595 Building Extensions
596 The Comprehensive Perl Archive Network (CPAN) offers a wealth of
597 extensions, some of which require a C compiler to build. Look in
598 <http://www.cpan.org/> for more information on CPAN.
599
600 Note that not all of the extensions available from CPAN may work in
601 the Windows environment; you should check the information at
602 <http://www.cpantesters.org/> before investing too much effort into
603 porting modules that don't readily build.
604
605 Most extensions (whether they require a C compiler or not) can be
606 built, tested and installed with the standard mantra:
607
608 perl Makefile.PL
609 $MAKE
610 $MAKE test
611 $MAKE install
612
613 where $MAKE is whatever 'make' program you have configured perl to
614 use. Use "perl -V:make" to find out what this is. Some extensions
615 may not provide a testsuite (so "$MAKE test" may not do anything or
616 fail), but most serious ones do.
617
618 It is important that you use a supported 'make' program, and ensure
619 Config.pm knows about it. If you don't have nmake, you can either
620 get dmake from the location mentioned earlier or get an old version
621 of nmake reportedly available from:
622
623 <http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/nmake15.exe>
624
625 Another option is to use the make written in Perl, available from
626 CPAN.
627
628 <http://www.cpan.org/modules/by-module/Make/>
629
630 You may also use dmake. See "Make" above on how to get it.
631
632 Note that MakeMaker actually emits makefiles with different syntax
633 depending on what 'make' it thinks you are using. Therefore, it is
634 important that one of the following values appears in Config.pm:
635
636 make='nmake' # MakeMaker emits nmake syntax
637 make='dmake' # MakeMaker emits dmake syntax
638 any other value # MakeMaker emits generic make syntax
639 (e.g GNU make, or Perl make)
640
641 If the value doesn't match the 'make' program you want to use, edit
642 Config.pm to fix it.
643
644 If a module implements XSUBs, you will need one of the supported C
645 compilers. You must make sure you have set up the environment for
646 the compiler for command-line compilation before running "perl
647 Makefile.PL" or any invocation of make.
648
649 If a module does not build for some reason, look carefully for why
650 it failed, and report problems to the module author. If it looks
651 like the extension building support is at fault, report that with
652 full details of how the build failed using the perlbug utility.
653
654 Command-line Wildcard Expansion
655 The default command shells on DOS descendant operating systems
656 (such as they are) usually do not expand wildcard arguments
657 supplied to programs. They consider it the application's job to
658 handle that. This is commonly achieved by linking the application
659 (in our case, perl) with startup code that the C runtime libraries
660 usually provide. However, doing that results in incompatible perl
661 versions (since the behavior of the argv expansion code differs
662 depending on the compiler, and it is even buggy on some compilers).
663 Besides, it may be a source of frustration if you use such a perl
664 binary with an alternate shell that *does* expand wildcards.
665
666 Instead, the following solution works rather well. The nice things
667 about it are 1) you can start using it right away; 2) it is more
668 powerful, because it will do the right thing with a pattern like
669 */*/*.c; 3) you can decide whether you do/don't want to use it; and
670 4) you can extend the method to add any customizations (or even
671 entirely different kinds of wildcard expansion).
672
673 C:\> copy con c:\perl\lib\Wild.pm
674 # Wild.pm - emulate shell @ARGV expansion on shells that don't
675 use File::DosGlob;
676 @ARGV = map {
677 my @g = File::DosGlob::glob($_) if /[*?]/;
678 @g ? @g : $_;
679 } @ARGV;
680 1;
681 ^Z
682 C:\> set PERL5OPT=-MWild
683 C:\> perl -le "for (@ARGV) { print }" */*/perl*.c
684 p4view/perl/perl.c
685 p4view/perl/perlio.c
686 p4view/perl/perly.c
687 perl5.005/win32/perlglob.c
688 perl5.005/win32/perllib.c
689 perl5.005/win32/perlglob.c
690 perl5.005/win32/perllib.c
691 perl5.005/win32/perlglob.c
692 perl5.005/win32/perllib.c
693
694 Note there are two distinct steps there: 1) You'll have to create
695 Wild.pm and put it in your perl lib directory. 2) You'll need to
696 set the PERL5OPT environment variable. If you want argv expansion
697 to be the default, just set PERL5OPT in your default startup
698 environment.
699
700 If you are using the Visual C compiler, you can get the C runtime's
701 command line wildcard expansion built into perl binary. The
702 resulting binary will always expand unquoted command lines, which
703 may not be what you want if you use a shell that does that for you.
704 The expansion done is also somewhat less powerful than the approach
705 suggested above.
706
707 Notes on 64-bit Windows
708 Windows .NET Server supports the LLP64 data model on the Intel
709 Itanium architecture.
710
711 The LLP64 data model is different from the LP64 data model that is
712 the norm on 64-bit Unix platforms. In the former, "int" and "long"
713 are both 32-bit data types, while pointers are 64 bits wide. In
714 addition, there is a separate 64-bit wide integral type, "__int64".
715 In contrast, the LP64 data model that is pervasive on Unix
716 platforms provides "int" as the 32-bit type, while both the "long"
717 type and pointers are of 64-bit precision. Note that both models
718 provide for 64-bits of addressability.
719
720 64-bit Windows running on Itanium is capable of running 32-bit x86
721 binaries transparently. This means that you could use a 32-bit
722 build of Perl on a 64-bit system. Given this, why would one want
723 to build a 64-bit build of Perl? Here are some reasons why you
724 would bother:
725
726 · A 64-bit native application will run much more efficiently on
727 Itanium hardware.
728
729 · There is no 2GB limit on process size.
730
731 · Perl automatically provides large file support when built under
732 64-bit Windows.
733
734 · Embedding Perl inside a 64-bit application.
735
736 Running Perl Scripts
737 Perl scripts on UNIX use the "#!" (a.k.a "shebang") line to indicate to
738 the OS that it should execute the file using perl. Windows has no
739 comparable means to indicate arbitrary files are executables.
740
741 Instead, all available methods to execute plain text files on Windows
742 rely on the file "extension". There are three methods to use this to
743 execute perl scripts:
744
745 1. There is a facility called "file extension associations". This
746 can be manipulated via the two commands "assoc" and "ftype"
747 that come standard with Windows. Type "ftype /?" for a
748 complete example of how to set this up for perl scripts (Say
749 what? You thought Windows wasn't perl-ready? :).
750
751 2. Since file associations don't work everywhere, and there are
752 reportedly bugs with file associations where it does work, the
753 old method of wrapping the perl script to make it look like a
754 regular batch file to the OS, may be used. The install process
755 makes available the "pl2bat.bat" script which can be used to
756 wrap perl scripts into batch files. For example:
757
758 pl2bat foo.pl
759
760 will create the file "FOO.BAT". Note "pl2bat" strips any .pl
761 suffix and adds a .bat suffix to the generated file.
762
763 If you use the 4DOS/NT or similar command shell, note that
764 "pl2bat" uses the "%*" variable in the generated batch file to
765 refer to all the command line arguments, so you may need to
766 make sure that construct works in batch files. As of this
767 writing, 4DOS/NT users will need a "ParameterChar = *"
768 statement in their 4NT.INI file or will need to execute "setdos
769 /p*" in the 4DOS/NT startup file to enable this to work.
770
771 3. Using "pl2bat" has a few problems: the file name gets changed,
772 so scripts that rely on $0 to find what they must do may not
773 run properly; running "pl2bat" replicates the contents of the
774 original script, and so this process can be maintenance
775 intensive if the originals get updated often. A different
776 approach that avoids both problems is possible.
777
778 A script called "runperl.bat" is available that can be copied
779 to any filename (along with the .bat suffix). For example, if
780 you call it "foo.bat", it will run the file "foo" when it is
781 executed. Since you can run batch files on Windows platforms
782 simply by typing the name (without the extension), this
783 effectively runs the file "foo", when you type either "foo" or
784 "foo.bat". With this method, "foo.bat" can even be in a
785 different location than the file "foo", as long as "foo" is
786 available somewhere on the PATH. If your scripts are on a
787 filesystem that allows symbolic links, you can even avoid
788 copying "runperl.bat".
789
790 Here's a diversion: copy "runperl.bat" to "runperl", and type
791 "runperl". Explain the observed behavior, or lack thereof. :)
792 Hint: .gnidnats llits er'uoy fi ,"lrepnur" eteled :tniH
793
794 Miscellaneous Things
795 A full set of HTML documentation is installed, so you should be able to
796 use it if you have a web browser installed on your system.
797
798 "perldoc" is also a useful tool for browsing information contained in
799 the documentation, especially in conjunction with a pager like "less"
800 (recent versions of which have Windows support). You may have to set
801 the PAGER environment variable to use a specific pager. "perldoc -f
802 foo" will print information about the perl operator "foo".
803
804 One common mistake when using this port with a GUI library like "Tk" is
805 assuming that Perl's normal behavior of opening a command-line window
806 will go away. This isn't the case. If you want to start a copy of
807 "perl" without opening a command-line window, use the "wperl"
808 executable built during the installation process. Usage is exactly the
809 same as normal "perl" on Windows, except that options like "-h" don't
810 work (since they need a command-line window to print to).
811
812 If you find bugs in perl, you can run "perlbug" to create a bug report
813 (you may have to send it manually if "perlbug" cannot find a mailer on
814 your system).
815
817 Norton AntiVirus interferes with the build process, particularly if set
818 to "AutoProtect, All Files, when Opened". Unlike large applications the
819 perl build process opens and modifies a lot of files. Having the the
820 AntiVirus scan each and every one slows build the process
821 significantly. Worse, with PERLIO=stdio the build process fails with
822 peculiar messages as the virus checker interacts badly with
823 miniperl.exe writing configure files (it seems to either catch file
824 part written and treat it as suspicious, or virus checker may have it
825 "locked" in a way which inhibits miniperl updating it). The build does
826 complete with
827
828 set PERLIO=perlio
829
830 but that may be just luck. Other AntiVirus software may have similar
831 issues.
832
833 A git GUI shell extension for Windows such as TortoiseGit will cause
834 the build and later "make test" to run much slower since every file is
835 checked for its git status as soon as it is created and/or modified.
836 TortoiseGit doesn't cause any test failures or build problems unlike
837 the antivirus software described above, but it does cause similar
838 slowness. It is suggested to use Task Manager to look for background
839 processes which use high CPU amounts during the building process.
840
841 Some of the built-in functions do not act exactly as documented in
842 perlfunc, and a few are not implemented at all. To avoid surprises,
843 particularly if you have had prior exposure to Perl in other operating
844 environments or if you intend to write code that will be portable to
845 other environments, see perlport for a reasonably definitive list of
846 these differences.
847
848 Not all extensions available from CPAN may build or work properly in
849 the Windows environment. See "Building Extensions".
850
851 Most "socket()" related calls are supported, but they may not behave as
852 on Unix platforms. See perlport for the full list.
853
854 Signal handling may not behave as on Unix platforms (where it doesn't
855 exactly "behave", either :). For instance, calling "die()" or "exit()"
856 from signal handlers will cause an exception, since most
857 implementations of "signal()" on Windows are severely crippled. Thus,
858 signals may work only for simple things like setting a flag variable in
859 the handler. Using signals under this port should currently be
860 considered unsupported.
861
862 Please send detailed descriptions of any problems and solutions that
863 you may find to <perlbug@perl.org>, along with the output produced by
864 "perl -V".
865
867 The use of a camel with the topic of Perl is a trademark of O'Reilly
868 and Associates, Inc. Used with permission.
869
871 Gary Ng <71564.1743@CompuServe.COM>
872 Gurusamy Sarathy <gsar@activestate.com>
873 Nick Ing-Simmons <nick@ing-simmons.net>
874 Jan Dubois <jand@activestate.com>
875 Steve Hay <steve.m.hay@googlemail.com>
876
877 This document is maintained by Jan Dubois.
878
880 perl
881
883 This port was originally contributed by Gary Ng around 5.003_24, and
884 borrowed from the Hip Communications port that was available at the
885 time. Various people have made numerous and sundry hacks since then.
886
887 GCC/mingw32 support was added in 5.005 (Nick Ing-Simmons).
888
889 Support for PERL_OBJECT was added in 5.005 (ActiveState Tool Corp).
890
891 Support for fork() emulation was added in 5.6 (ActiveState Tool Corp).
892
893 Win9x support was added in 5.6 (Benjamin Stuhl).
894
895 Support for 64-bit Windows added in 5.8 (ActiveState Corp).
896
897 Last updated: 16 June 2017
898
899
900
901perl v5.26.3 2018-03-23 PERLWIN32(1)