-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiref.html
More file actions
2084 lines (1961 loc) · 193 KB
/
apiref.html
File metadata and controls
2084 lines (1961 loc) · 193 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_TW">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>10. API參照 — Python 3.7.0 說明文件</title>
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/translations.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.7.0 說明文件 中搜尋"
href="../_static/opensearch.xml"/>
<link rel="author" title="關於這些文件" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜尋" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="安裝 Python 模組(舊版)" href="../install/index.html" />
<link rel="prev" title="9. 指令參照" href="commandref.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/3/distutils/apiref.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="../install/index.html" title="安裝 Python 模組(舊版)"
accesskey="N">下一頁</a> |</li>
<li class="right" >
<a href="commandref.html" title="9. 指令參照"
accesskey="P">上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">發布 Python 模組(舊版)</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="api-reference">
<span id="id1"></span><h1>10. API參照<a class="headerlink" href="#api-reference" title="本標題的永久連結">¶</a></h1>
<div class="section" id="module-distutils.core">
<span id="distutils-core-core-distutils-functionality"></span><h2>10.1. <a class="reference internal" href="#module-distutils.core" title="distutils.core: The core Distutils functionality"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.core</span></code></a> — Core Distutils functionality<a class="headerlink" href="#module-distutils.core" title="本標題的永久連結">¶</a></h2>
<p>The <a class="reference internal" href="#module-distutils.core" title="distutils.core: The core Distutils functionality"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.core</span></code></a> module is the only module that needs to be installed
to use the Distutils. It provides the <a class="reference internal" href="#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a> (which is called from the
setup script). Indirectly provides the <code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.dist.Distribution</span></code> and
<a class="reference internal" href="#distutils.cmd.Command" title="distutils.cmd.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.cmd.Command</span></code></a> class.</p>
<dl class="function">
<dt id="distutils.core.setup">
<code class="descclassname">distutils.core.</code><code class="descname">setup</code><span class="sig-paren">(</span><em>arguments</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.core.setup" title="本定義的永久連結">¶</a></dt>
<dd><p>The basic do-everything function that does most everything you could ever ask
for from a Distutils method.</p>
<p>The setup function takes a large number of arguments. These are laid out in the
following table.</p>
<table border="1" class="docutils">
<colgroup>
<col width="18%" />
<col width="28%" />
<col width="54%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">argument name</th>
<th class="head">value</th>
<th class="head">type</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><em>name</em></td>
<td>The name of the package</td>
<td>a string</td>
</tr>
<tr class="row-odd"><td><em>version</em></td>
<td>The version number of the
package; see
<a class="reference internal" href="#module-distutils.version" title="distutils.version: implements classes that represent module version numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.version</span></code></a></td>
<td>a string</td>
</tr>
<tr class="row-even"><td><em>description</em></td>
<td>A single line describing the
package</td>
<td>a string</td>
</tr>
<tr class="row-odd"><td><em>long_description</em></td>
<td>Longer description of the
package</td>
<td>a string</td>
</tr>
<tr class="row-even"><td><em>author</em></td>
<td>The name of the package author</td>
<td>a string</td>
</tr>
<tr class="row-odd"><td><em>author_email</em></td>
<td>The email address of the
package author</td>
<td>a string</td>
</tr>
<tr class="row-even"><td><em>maintainer</em></td>
<td>The name of the current
maintainer, if different from
the author. Note that if
the maintainer is provided,
distutils will use it as the
author in <code class="file docutils literal notranslate"><span class="pre">PKG-INFO</span></code></td>
<td>a string</td>
</tr>
<tr class="row-odd"><td><em>maintainer_email</em></td>
<td>The email address of the
current maintainer, if
different from the author</td>
<td>a string</td>
</tr>
<tr class="row-even"><td><em>url</em></td>
<td>A URL for the package
(homepage)</td>
<td>a string</td>
</tr>
<tr class="row-odd"><td><em>download_url</em></td>
<td>A URL to download the package</td>
<td>a string</td>
</tr>
<tr class="row-even"><td><em>packages</em></td>
<td>A list of Python packages that
distutils will manipulate</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>py_modules</em></td>
<td>A list of Python modules that
distutils will manipulate</td>
<td>a list of strings</td>
</tr>
<tr class="row-even"><td><em>scripts</em></td>
<td>A list of standalone script
files to be built and
installed</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>ext_modules</em></td>
<td>A list of Python extensions to
be built</td>
<td>a list of instances of
<a class="reference internal" href="#distutils.core.Extension" title="distutils.core.Extension"><code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.core.Extension</span></code></a></td>
</tr>
<tr class="row-even"><td><em>classifiers</em></td>
<td>A list of categories for the
package</td>
<td>a list of strings; valid classifiers are listed on <a class="reference external" href="https://pypi.org/classifiers">PyPI</a>.</td>
</tr>
<tr class="row-odd"><td><em>distclass</em></td>
<td>the <a class="reference internal" href="#distutils.core.Distribution" title="distutils.core.Distribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code></a>
class to use</td>
<td>a subclass of
<a class="reference internal" href="#distutils.core.Distribution" title="distutils.core.Distribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.core.Distribution</span></code></a></td>
</tr>
<tr class="row-even"><td><em>script_name</em></td>
<td>The name of the setup.py
script - defaults to
<code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code></td>
<td>a string</td>
</tr>
<tr class="row-odd"><td><em>script_args</em></td>
<td>Arguments to supply to the
setup script</td>
<td>a list of strings</td>
</tr>
<tr class="row-even"><td><em>options</em></td>
<td>default options for the setup
script</td>
<td>a dictionary</td>
</tr>
<tr class="row-odd"><td><em>license</em></td>
<td>The license for the package</td>
<td>a string</td>
</tr>
<tr class="row-even"><td><em>keywords</em></td>
<td>Descriptive meta-data, see
<span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0314"><strong>PEP 314</strong></a></td>
<td>a list of strings or a comma-separated string</td>
</tr>
<tr class="row-odd"><td><em>platforms</em></td>
<td> </td>
<td>a list of strings or a comma-separated string</td>
</tr>
<tr class="row-even"><td><em>cmdclass</em></td>
<td>A mapping of command names to
<a class="reference internal" href="#distutils.core.Command" title="distutils.core.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">Command</span></code></a> subclasses</td>
<td>a dictionary</td>
</tr>
<tr class="row-odd"><td><em>data_files</em></td>
<td>A list of data files to
install</td>
<td>a list</td>
</tr>
<tr class="row-even"><td><em>package_dir</em></td>
<td>A mapping of package to
directory names</td>
<td>a dictionary</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="distutils.core.run_setup">
<code class="descclassname">distutils.core.</code><code class="descname">run_setup</code><span class="sig-paren">(</span><em>script_name</em><span class="optional">[</span>, <em>script_args=None</em>, <em>stop_after='run'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.core.run_setup" title="本定義的永久連結">¶</a></dt>
<dd><p>Run a setup script in a somewhat controlled environment, and return the
<code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.dist.Distribution</span></code> instance that drives things. This is
useful if you need to find out the distribution meta-data (passed as keyword
args from <em>script</em> to <a class="reference internal" href="#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a>), or the contents of the config files or
command-line.</p>
<p><em>script_name</em> is a file that will be read and run with <a class="reference internal" href="../library/functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a>. <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code>
will be replaced with <em>script</em> for the duration of the call. <em>script_args</em> is a
list of strings; if supplied, <code class="docutils literal notranslate"><span class="pre">sys.argv[1:]</span></code> will be replaced by <em>script_args</em>
for the duration of the call.</p>
<p><em>stop_after</em> tells <a class="reference internal" href="#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a> when to stop processing; possible values:</p>
<table border="1" class="docutils">
<colgroup>
<col width="25%" />
<col width="75%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">value</th>
<th class="head">description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><em>init</em></td>
<td>Stop after the <a class="reference internal" href="#distutils.core.Distribution" title="distutils.core.Distribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code></a>
instance has been created and populated
with the keyword arguments to <a class="reference internal" href="#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a></td>
</tr>
<tr class="row-odd"><td><em>config</em></td>
<td>Stop after config files have been parsed
(and their data stored in the
<a class="reference internal" href="#distutils.core.Distribution" title="distutils.core.Distribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code></a> instance)</td>
</tr>
<tr class="row-even"><td><em>commandline</em></td>
<td>Stop after the command-line
(<code class="docutils literal notranslate"><span class="pre">sys.argv[1:]</span></code> or <em>script_args</em>) have
been parsed (and the data stored in the
<a class="reference internal" href="#distutils.core.Distribution" title="distutils.core.Distribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code></a> instance.)</td>
</tr>
<tr class="row-odd"><td><em>run</em></td>
<td>Stop after all commands have been run (the
same as if <a class="reference internal" href="#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a> had been called
in the usual way). This is the default
value.</td>
</tr>
</tbody>
</table>
</dd></dl>
<p>In addition, the <a class="reference internal" href="#module-distutils.core" title="distutils.core: The core Distutils functionality"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.core</span></code></a> module exposed a number of classes that
live elsewhere.</p>
<ul class="simple">
<li><code class="xref py py-class docutils literal notranslate"><span class="pre">Extension</span></code> from <a class="reference internal" href="#module-distutils.extension" title="distutils.extension: Provides the Extension class, used to describe C/C++ extension modules in setup scripts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.extension</span></code></a></li>
<li><a class="reference internal" href="#distutils.cmd.Command" title="distutils.cmd.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">Command</span></code></a> from <a class="reference internal" href="#module-distutils.cmd" title="distutils.cmd: This module provides the abstract base class Command. This class is subclassed by the modules in the distutils.command subpackage."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.cmd</span></code></a></li>
<li><code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code> from <a class="reference internal" href="#module-distutils.dist" title="distutils.dist: Provides the Distribution class, which represents the module distribution being built/installed/distributed"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.dist</span></code></a></li>
</ul>
<p>A short description of each of these follows, but see the relevant module for
the full reference.</p>
<dl class="class">
<dt id="distutils.core.Extension">
<em class="property">class </em><code class="descclassname">distutils.core.</code><code class="descname">Extension</code><a class="headerlink" href="#distutils.core.Extension" title="本定義的永久連結">¶</a></dt>
<dd><p>The Extension class describes a single C or C++ extension module in a setup
script. It accepts the following keyword arguments in its constructor:</p>
<table border="1" class="docutils">
<colgroup>
<col width="29%" />
<col width="39%" />
<col width="33%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">argument name</th>
<th class="head">value</th>
<th class="head">type</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><em>name</em></td>
<td>the full name of the
extension, including any
packages — ie. <em>not</em> a
filename or pathname, but
Python dotted name</td>
<td>a string</td>
</tr>
<tr class="row-odd"><td><em>sources</em></td>
<td>list of source filenames,
relative to the distribution
root (where the setup script
lives), in Unix form (slash-
separated) for portability.
Source files may be C, C++,
SWIG (.i), platform-specific
resource files, or whatever
else is recognized by the
<strong class="command">build_ext</strong> command
as source for a Python
extension.</td>
<td>a list of strings</td>
</tr>
<tr class="row-even"><td><em>include_dirs</em></td>
<td>list of directories to search
for C/C++ header files (in
Unix form for portability)</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>define_macros</em></td>
<td>list of macros to define; each
macro is defined using a
2-tuple <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code>,
where <em>value</em> is
either the string to define it
to or <code class="docutils literal notranslate"><span class="pre">None</span></code> to define it
without a particular value
(equivalent of <code class="docutils literal notranslate"><span class="pre">#define</span> <span class="pre">FOO</span></code>
in source or <code class="xref std std-option docutils literal notranslate"><span class="pre">-DFOO</span></code>
on Unix C compiler command
line)</td>
<td>a list of tuples</td>
</tr>
<tr class="row-even"><td><em>undef_macros</em></td>
<td>list of macros to undefine
explicitly</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>library_dirs</em></td>
<td>list of directories to search
for C/C++ libraries at link
time</td>
<td>a list of strings</td>
</tr>
<tr class="row-even"><td><em>libraries</em></td>
<td>list of library names (not
filenames or paths) to link
against</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>runtime_library_dirs</em></td>
<td>list of directories to search
for C/C++ libraries at run
time (for shared extensions,
this is when the extension is
loaded)</td>
<td>a list of strings</td>
</tr>
<tr class="row-even"><td><em>extra_objects</em></td>
<td>list of extra files to link
with (eg. object files not
implied by 『sources』, static
library that must be
explicitly specified, binary
resource files, etc.)</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>extra_compile_args</em></td>
<td>any extra platform- and
compiler-specific information
to use when compiling the
source files in 『sources』. For
platforms and compilers where
a command line makes sense,
this is typically a list of
command-line arguments, but
for other platforms it could
be anything.</td>
<td>a list of strings</td>
</tr>
<tr class="row-even"><td><em>extra_link_args</em></td>
<td>any extra platform- and
compiler-specific information
to use when linking object
files together to create the
extension (or to create a new
static Python interpreter).
Similar interpretation as for
『extra_compile_args』.</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>export_symbols</em></td>
<td>list of symbols to be exported
from a shared extension. Not
used on all platforms, and not
generally necessary for Python
extensions, which typically
export exactly one symbol:
<code class="docutils literal notranslate"><span class="pre">init</span></code> + extension_name.</td>
<td>a list of strings</td>
</tr>
<tr class="row-even"><td><em>depends</em></td>
<td>list of files that the
extension depends on</td>
<td>a list of strings</td>
</tr>
<tr class="row-odd"><td><em>language</em></td>
<td>extension language (i.e.
<code class="docutils literal notranslate"><span class="pre">'c'</span></code>, <code class="docutils literal notranslate"><span class="pre">'c++'</span></code>,
<code class="docutils literal notranslate"><span class="pre">'objc'</span></code>). Will be detected
from the source extensions if
not provided.</td>
<td>a string</td>
</tr>
<tr class="row-even"><td><em>optional</em></td>
<td>specifies that a build failure
in the extension should not
abort the build process, but
simply skip the extension.</td>
<td>a boolean</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="class">
<dt id="distutils.core.Distribution">
<em class="property">class </em><code class="descclassname">distutils.core.</code><code class="descname">Distribution</code><a class="headerlink" href="#distutils.core.Distribution" title="本定義的永久連結">¶</a></dt>
<dd><p>A <a class="reference internal" href="#distutils.core.Distribution" title="distutils.core.Distribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code></a> describes how to build, install and package up a Python
software package.</p>
<p>See the <a class="reference internal" href="#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a> function for a list of keyword arguments accepted by the
Distribution constructor. <a class="reference internal" href="#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a> creates a Distribution instance.</p>
<div class="versionchanged">
<p><span class="versionmodified">3.7 版更變: </span><a class="reference internal" href="#distutils.core.Distribution" title="distutils.core.Distribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code></a> now warns if <code class="docutils literal notranslate"><span class="pre">classifiers</span></code>,
<code class="docutils literal notranslate"><span class="pre">keywords</span></code> and <code class="docutils literal notranslate"><span class="pre">platforms</span></code> fields are not specified as a list or
a string.</p>
</div>
</dd></dl>
<dl class="class">
<dt id="distutils.core.Command">
<em class="property">class </em><code class="descclassname">distutils.core.</code><code class="descname">Command</code><a class="headerlink" href="#distutils.core.Command" title="本定義的永久連結">¶</a></dt>
<dd><p>A <a class="reference internal" href="#distutils.core.Command" title="distutils.core.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">Command</span></code></a> class (or rather, an instance of one of its subclasses)
implement a single distutils command.</p>
</dd></dl>
</div>
<div class="section" id="module-distutils.ccompiler">
<span id="distutils-ccompiler-ccompiler-base-class"></span><h2>10.2. <a class="reference internal" href="#module-distutils.ccompiler" title="distutils.ccompiler: Abstract CCompiler class"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.ccompiler</span></code></a> — CCompiler base class<a class="headerlink" href="#module-distutils.ccompiler" title="本標題的永久連結">¶</a></h2>
<p>This module provides the abstract base class for the <a class="reference internal" href="#distutils.ccompiler.CCompiler" title="distutils.ccompiler.CCompiler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code></a>
classes. A <a class="reference internal" href="#distutils.ccompiler.CCompiler" title="distutils.ccompiler.CCompiler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code></a> instance can be used for all the compile and
link steps needed to build a single project. Methods are provided to set
options for the compiler — macro definitions, include directories, link path,
libraries and the like.</p>
<p>This module provides the following functions.</p>
<dl class="function">
<dt id="distutils.ccompiler.gen_lib_options">
<code class="descclassname">distutils.ccompiler.</code><code class="descname">gen_lib_options</code><span class="sig-paren">(</span><em>compiler</em>, <em>library_dirs</em>, <em>runtime_library_dirs</em>, <em>libraries</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.gen_lib_options" title="本定義的永久連結">¶</a></dt>
<dd><p>Generate linker options for searching library directories and linking with
specific libraries. <em>libraries</em> and <em>library_dirs</em> are, respectively, lists of
library names (not filenames!) and search directories. Returns a list of
command-line options suitable for use with some compiler (depending on the two
format strings passed in).</p>
</dd></dl>
<dl class="function">
<dt id="distutils.ccompiler.gen_preprocess_options">
<code class="descclassname">distutils.ccompiler.</code><code class="descname">gen_preprocess_options</code><span class="sig-paren">(</span><em>macros</em>, <em>include_dirs</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.gen_preprocess_options" title="本定義的永久連結">¶</a></dt>
<dd><p>Generate C pre-processor options (<code class="xref std std-option docutils literal notranslate"><span class="pre">-D</span></code>, <code class="xref std std-option docutils literal notranslate"><span class="pre">-U</span></code>, <code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code>) as
used by at least two types of compilers: the typical Unix compiler and Visual
C++. <em>macros</em> is the usual thing, a list of 1- or 2-tuples, where <code class="docutils literal notranslate"><span class="pre">(name,)</span></code>
means undefine (<code class="xref std std-option docutils literal notranslate"><span class="pre">-U</span></code>) macro <em>name</em>, and <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code> means define
(<code class="xref std std-option docutils literal notranslate"><span class="pre">-D</span></code>) macro <em>name</em> to <em>value</em>. <em>include_dirs</em> is just a list of
directory names to be added to the header file search path (<code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code>).
Returns a list of command-line options suitable for either Unix compilers or
Visual C++.</p>
</dd></dl>
<dl class="function">
<dt id="distutils.ccompiler.get_default_compiler">
<code class="descclassname">distutils.ccompiler.</code><code class="descname">get_default_compiler</code><span class="sig-paren">(</span><em>osname</em>, <em>platform</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.get_default_compiler" title="本定義的永久連結">¶</a></dt>
<dd><p>Determine the default compiler to use for the given platform.</p>
<p><em>osname</em> should be one of the standard Python OS names (i.e. the ones returned
by <code class="docutils literal notranslate"><span class="pre">os.name</span></code>) and <em>platform</em> the common value returned by <code class="docutils literal notranslate"><span class="pre">sys.platform</span></code> for
the platform in question.</p>
<p>The default values are <code class="docutils literal notranslate"><span class="pre">os.name</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.platform</span></code> in case the parameters
are not given.</p>
</dd></dl>
<dl class="function">
<dt id="distutils.ccompiler.new_compiler">
<code class="descclassname">distutils.ccompiler.</code><code class="descname">new_compiler</code><span class="sig-paren">(</span><em>plat=None</em>, <em>compiler=None</em>, <em>verbose=0</em>, <em>dry_run=0</em>, <em>force=0</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.new_compiler" title="本定義的永久連結">¶</a></dt>
<dd><p>Factory function to generate an instance of some CCompiler subclass for the
supplied platform/compiler combination. <em>plat</em> defaults to <code class="docutils literal notranslate"><span class="pre">os.name</span></code> (eg.
<code class="docutils literal notranslate"><span class="pre">'posix'</span></code>, <code class="docutils literal notranslate"><span class="pre">'nt'</span></code>), and <em>compiler</em> defaults to the default compiler for
that platform. Currently only <code class="docutils literal notranslate"><span class="pre">'posix'</span></code> and <code class="docutils literal notranslate"><span class="pre">'nt'</span></code> are supported, and the
default compilers are 「traditional Unix interface」 (<code class="xref py py-class docutils literal notranslate"><span class="pre">UnixCCompiler</span></code>
class) and Visual C++ (<code class="xref py py-class docutils literal notranslate"><span class="pre">MSVCCompiler</span></code> class). Note that it’s perfectly
possible to ask for a Unix compiler object under Windows, and a Microsoft
compiler object under Unix—if you supply a value for <em>compiler</em>, <em>plat</em> is
ignored.</p>
</dd></dl>
<dl class="function">
<dt id="distutils.ccompiler.show_compilers">
<code class="descclassname">distutils.ccompiler.</code><code class="descname">show_compilers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.show_compilers" title="本定義的永久連結">¶</a></dt>
<dd><p>Print list of available compilers (used by the <code class="xref std std-option docutils literal notranslate"><span class="pre">--help-compiler</span></code> options
to <strong class="command">build</strong>, <strong class="command">build_ext</strong>, <strong class="command">build_clib</strong>).</p>
</dd></dl>
<dl class="class">
<dt id="distutils.ccompiler.CCompiler">
<em class="property">class </em><code class="descclassname">distutils.ccompiler.</code><code class="descname">CCompiler</code><span class="sig-paren">(</span><span class="optional">[</span><em>verbose=0</em>, <em>dry_run=0</em>, <em>force=0</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler" title="本定義的永久連結">¶</a></dt>
<dd><p>The abstract base class <a class="reference internal" href="#distutils.ccompiler.CCompiler" title="distutils.ccompiler.CCompiler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code></a> defines the interface that must be
implemented by real compiler classes. The class also has some utility methods
used by several compiler classes.</p>
<p>The basic idea behind a compiler abstraction class is that each instance can be
used for all the compile/link steps in building a single project. Thus,
attributes common to all of those compile and link steps — include
directories, macros to define, libraries to link against, etc. — are
attributes of the compiler instance. To allow for variability in how individual
files are treated, most of those attributes may be varied on a per-compilation
or per-link basis.</p>
<p>The constructor for each subclass creates an instance of the Compiler object.
Flags are <em>verbose</em> (show verbose output), <em>dry_run</em> (don’t actually execute the
steps) and <em>force</em> (rebuild everything, regardless of dependencies). All of
these flags default to <code class="docutils literal notranslate"><span class="pre">0</span></code> (off). Note that you probably don’t want to
instantiate <a class="reference internal" href="#distutils.ccompiler.CCompiler" title="distutils.ccompiler.CCompiler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code></a> or one of its subclasses directly - use the
<code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.CCompiler.new_compiler()</span></code> factory function instead.</p>
<p>The following methods allow you to manually alter compiler options for the
instance of the Compiler class.</p>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.add_include_dir">
<code class="descname">add_include_dir</code><span class="sig-paren">(</span><em>dir</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.add_include_dir" title="本定義的永久連結">¶</a></dt>
<dd><p>Add <em>dir</em> to the list of directories that will be searched for header files.
The compiler is instructed to search directories in the order in which they are
supplied by successive calls to <a class="reference internal" href="#distutils.ccompiler.CCompiler.add_include_dir" title="distutils.ccompiler.CCompiler.add_include_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_include_dir()</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.set_include_dirs">
<code class="descname">set_include_dirs</code><span class="sig-paren">(</span><em>dirs</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.set_include_dirs" title="本定義的永久連結">¶</a></dt>
<dd><p>Set the list of directories that will be searched to <em>dirs</em> (a list of strings).
Overrides any preceding calls to <a class="reference internal" href="#distutils.ccompiler.CCompiler.add_include_dir" title="distutils.ccompiler.CCompiler.add_include_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_include_dir()</span></code></a>; subsequent calls to
<a class="reference internal" href="#distutils.ccompiler.CCompiler.add_include_dir" title="distutils.ccompiler.CCompiler.add_include_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_include_dir()</span></code></a> add to the list passed to <a class="reference internal" href="#distutils.ccompiler.CCompiler.set_include_dirs" title="distutils.ccompiler.CCompiler.set_include_dirs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_include_dirs()</span></code></a>.
This does not affect any list of standard include directories that the compiler
may search by default.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.add_library">
<code class="descname">add_library</code><span class="sig-paren">(</span><em>libname</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.add_library" title="本定義的永久連結">¶</a></dt>
<dd><p>Add <em>libname</em> to the list of libraries that will be included in all links driven
by this compiler object. Note that <em>libname</em> should *not* be the name of a
file containing a library, but the name of the library itself: the actual
filename will be inferred by the linker, the compiler, or the compiler class
(depending on the platform).</p>
<p>The linker will be instructed to link against libraries in the order they were
supplied to <a class="reference internal" href="#distutils.ccompiler.CCompiler.add_library" title="distutils.ccompiler.CCompiler.add_library"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_library()</span></code></a> and/or <a class="reference internal" href="#distutils.ccompiler.CCompiler.set_libraries" title="distutils.ccompiler.CCompiler.set_libraries"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_libraries()</span></code></a>. It is perfectly
valid to duplicate library names; the linker will be instructed to link against
libraries as many times as they are mentioned.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.set_libraries">
<code class="descname">set_libraries</code><span class="sig-paren">(</span><em>libnames</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.set_libraries" title="本定義的永久連結">¶</a></dt>
<dd><p>Set the list of libraries to be included in all links driven by this compiler
object to <em>libnames</em> (a list of strings). This does not affect any standard
system libraries that the linker may include by default.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.add_library_dir">
<code class="descname">add_library_dir</code><span class="sig-paren">(</span><em>dir</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.add_library_dir" title="本定義的永久連結">¶</a></dt>
<dd><p>Add <em>dir</em> to the list of directories that will be searched for libraries
specified to <a class="reference internal" href="#distutils.ccompiler.CCompiler.add_library" title="distutils.ccompiler.CCompiler.add_library"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_library()</span></code></a> and <a class="reference internal" href="#distutils.ccompiler.CCompiler.set_libraries" title="distutils.ccompiler.CCompiler.set_libraries"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_libraries()</span></code></a>. The linker will be
instructed to search for libraries in the order they are supplied to
<a class="reference internal" href="#distutils.ccompiler.CCompiler.add_library_dir" title="distutils.ccompiler.CCompiler.add_library_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_library_dir()</span></code></a> and/or <a class="reference internal" href="#distutils.ccompiler.CCompiler.set_library_dirs" title="distutils.ccompiler.CCompiler.set_library_dirs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_library_dirs()</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.set_library_dirs">
<code class="descname">set_library_dirs</code><span class="sig-paren">(</span><em>dirs</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.set_library_dirs" title="本定義的永久連結">¶</a></dt>
<dd><p>Set the list of library search directories to <em>dirs</em> (a list of strings). This
does not affect any standard library search path that the linker may search by
default.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.add_runtime_library_dir">
<code class="descname">add_runtime_library_dir</code><span class="sig-paren">(</span><em>dir</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.add_runtime_library_dir" title="本定義的永久連結">¶</a></dt>
<dd><p>Add <em>dir</em> to the list of directories that will be searched for shared libraries
at runtime.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.set_runtime_library_dirs">
<code class="descname">set_runtime_library_dirs</code><span class="sig-paren">(</span><em>dirs</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.set_runtime_library_dirs" title="本定義的永久連結">¶</a></dt>
<dd><p>Set the list of directories to search for shared libraries at runtime to <em>dirs</em>
(a list of strings). This does not affect any standard search path that the
runtime linker may search by default.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.define_macro">
<code class="descname">define_macro</code><span class="sig-paren">(</span><em>name</em><span class="optional">[</span>, <em>value=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.define_macro" title="本定義的永久連結">¶</a></dt>
<dd><p>Define a preprocessor macro for all compilations driven by this compiler object.
The optional parameter <em>value</em> should be a string; if it is not supplied, then
the macro will be defined without an explicit value and the exact outcome
depends on the compiler used.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.undefine_macro">
<code class="descname">undefine_macro</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.undefine_macro" title="本定義的永久連結">¶</a></dt>
<dd><p>Undefine a preprocessor macro for all compilations driven by this compiler
object. If the same macro is defined by <a class="reference internal" href="#distutils.ccompiler.CCompiler.define_macro" title="distutils.ccompiler.CCompiler.define_macro"><code class="xref py py-meth docutils literal notranslate"><span class="pre">define_macro()</span></code></a> and
undefined by <a class="reference internal" href="#distutils.ccompiler.CCompiler.undefine_macro" title="distutils.ccompiler.CCompiler.undefine_macro"><code class="xref py py-meth docutils literal notranslate"><span class="pre">undefine_macro()</span></code></a> the last call takes precedence
(including multiple redefinitions or undefinitions). If the macro is
redefined/undefined on a per-compilation basis (ie. in the call to
<a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compile()</span></code></a>), then that takes precedence.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.add_link_object">
<code class="descname">add_link_object</code><span class="sig-paren">(</span><em>object</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.add_link_object" title="本定義的永久連結">¶</a></dt>
<dd><p>Add <em>object</em> to the list of object files (or analogues, such as explicitly named
library files or the output of 「resource compilers」) to be included in every
link driven by this compiler object.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.set_link_objects">
<code class="descname">set_link_objects</code><span class="sig-paren">(</span><em>objects</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.set_link_objects" title="本定義的永久連結">¶</a></dt>
<dd><p>Set the list of object files (or analogues) to be included in every link to
<em>objects</em>. This does not affect any standard object files that the linker may
include by default (such as system libraries).</p>
</dd></dl>
<p>The following methods implement methods for autodetection of compiler options,
providing some functionality similar to GNU <strong class="program">autoconf</strong>.</p>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.detect_language">
<code class="descname">detect_language</code><span class="sig-paren">(</span><em>sources</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.detect_language" title="本定義的永久連結">¶</a></dt>
<dd><p>Detect the language of a given file, or list of files. Uses the instance
attributes <code class="xref py py-attr docutils literal notranslate"><span class="pre">language_map</span></code> (a dictionary), and <code class="xref py py-attr docutils literal notranslate"><span class="pre">language_order</span></code> (a
list) to do the job.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.find_library_file">
<code class="descname">find_library_file</code><span class="sig-paren">(</span><em>dirs</em>, <em>lib</em><span class="optional">[</span>, <em>debug=0</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.find_library_file" title="本定義的永久連結">¶</a></dt>
<dd><p>Search the specified list of directories for a static or shared library file
<em>lib</em> and return the full path to that file. If <em>debug</em> is true, look for a
debugging version (if that makes sense on the current platform). Return
<code class="docutils literal notranslate"><span class="pre">None</span></code> if <em>lib</em> wasn’t found in any of the specified directories.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.has_function">
<code class="descname">has_function</code><span class="sig-paren">(</span><em>funcname</em><span class="optional">[</span>, <em>includes=None</em>, <em>include_dirs=None</em>, <em>libraries=None</em>, <em>library_dirs=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.has_function" title="本定義的永久連結">¶</a></dt>
<dd><p>Return a boolean indicating whether <em>funcname</em> is supported on the current
platform. The optional arguments can be used to augment the compilation
environment by providing additional include files and paths and libraries and
paths.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.library_dir_option">
<code class="descname">library_dir_option</code><span class="sig-paren">(</span><em>dir</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.library_dir_option" title="本定義的永久連結">¶</a></dt>
<dd><p>Return the compiler option to add <em>dir</em> to the list of directories searched for
libraries.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.library_option">
<code class="descname">library_option</code><span class="sig-paren">(</span><em>lib</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.library_option" title="本定義的永久連結">¶</a></dt>
<dd><p>Return the compiler option to add <em>lib</em> to the list of libraries linked into the
shared library or executable.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.runtime_library_dir_option">
<code class="descname">runtime_library_dir_option</code><span class="sig-paren">(</span><em>dir</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.runtime_library_dir_option" title="本定義的永久連結">¶</a></dt>
<dd><p>Return the compiler option to add <em>dir</em> to the list of directories searched for
runtime libraries.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.set_executables">
<code class="descname">set_executables</code><span class="sig-paren">(</span><em>**args</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.set_executables" title="本定義的永久連結">¶</a></dt>
<dd><p>Define the executables (and options for them) that will be run to perform the
various stages of compilation. The exact set of executables that may be
specified here depends on the compiler class (via the 『executables』 class
attribute), but most will have:</p>
<table border="1" class="docutils">
<colgroup>
<col width="25%" />
<col width="75%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">attribute</th>
<th class="head">description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><em>compiler</em></td>
<td>the C/C++ compiler</td>
</tr>
<tr class="row-odd"><td><em>linker_so</em></td>
<td>linker used to create shared objects and
libraries</td>
</tr>
<tr class="row-even"><td><em>linker_exe</em></td>
<td>linker used to create binary executables</td>
</tr>
<tr class="row-odd"><td><em>archiver</em></td>
<td>static library creator</td>
</tr>
</tbody>
</table>
<p>On platforms with a command-line (Unix, DOS/Windows), each of these is a string
that will be split into executable name and (optional) list of arguments.
(Splitting the string is done similarly to how Unix shells operate: words are
delimited by spaces, but quotes and backslashes can override this. See
<a class="reference internal" href="#distutils.util.split_quoted" title="distutils.util.split_quoted"><code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.util.split_quoted()</span></code></a>.)</p>
</dd></dl>
<p>The following methods invoke stages in the build process.</p>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.compile">
<code class="descname">compile</code><span class="sig-paren">(</span><em>sources</em><span class="optional">[</span>, <em>output_dir=None</em>, <em>macros=None</em>, <em>include_dirs=None</em>, <em>debug=0</em>, <em>extra_preargs=None</em>, <em>extra_postargs=None</em>, <em>depends=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.compile" title="本定義的永久連結">¶</a></dt>
<dd><p>Compile one or more source files. Generates object files (e.g. transforms a
<code class="file docutils literal notranslate"><span class="pre">.c</span></code> file to a <code class="file docutils literal notranslate"><span class="pre">.o</span></code> file.)</p>
<p><em>sources</em> must be a list of filenames, most likely C/C++ files, but in reality
anything that can be handled by a particular compiler and compiler class (eg.
<code class="xref py py-class docutils literal notranslate"><span class="pre">MSVCCompiler</span></code> can handle resource files in <em>sources</em>). Return a list of
object filenames, one per source filename in <em>sources</em>. Depending on the
implementation, not all source files will necessarily be compiled, but all
corresponding object filenames will be returned.</p>
<p>If <em>output_dir</em> is given, object files will be put under it, while retaining
their original path component. That is, <code class="file docutils literal notranslate"><span class="pre">foo/bar.c</span></code> normally compiles to
<code class="file docutils literal notranslate"><span class="pre">foo/bar.o</span></code> (for a Unix implementation); if <em>output_dir</em> is <em>build</em>, then
it would compile to <code class="file docutils literal notranslate"><span class="pre">build/foo/bar.o</span></code>.</p>
<p><em>macros</em>, if given, must be a list of macro definitions. A macro definition is
either a <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">value)</span></code> 2-tuple or a <code class="docutils literal notranslate"><span class="pre">(name,)</span></code> 1-tuple. The former defines
a macro; if the value is <code class="docutils literal notranslate"><span class="pre">None</span></code>, the macro is defined without an explicit
value. The 1-tuple case undefines a macro. Later
definitions/redefinitions/undefinitions take precedence.</p>
<p><em>include_dirs</em>, if given, must be a list of strings, the directories to add to
the default include file search path for this compilation only.</p>
<p><em>debug</em> is a boolean; if true, the compiler will be instructed to output debug
symbols in (or alongside) the object file(s).</p>
<p><em>extra_preargs</em> and <em>extra_postargs</em> are implementation-dependent. On platforms
that have the notion of a command-line (e.g. Unix, DOS/Windows), they are most
likely lists of strings: extra command-line arguments to prepend/append to the
compiler command line. On other platforms, consult the implementation class
documentation. In any event, they are intended as an escape hatch for those
occasions when the abstract compiler framework doesn’t cut the mustard.</p>
<p><em>depends</em>, if given, is a list of filenames that all targets depend on. If a
source file is older than any file in depends, then the source file will be
recompiled. This supports dependency tracking, but only at a coarse
granularity.</p>
<p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">CompileError</span></code> on failure.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.create_static_lib">
<code class="descname">create_static_lib</code><span class="sig-paren">(</span><em>objects</em>, <em>output_libname</em><span class="optional">[</span>, <em>output_dir=None</em>, <em>debug=0</em>, <em>target_lang=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.create_static_lib" title="本定義的永久連結">¶</a></dt>
<dd><p>Link a bunch of stuff together to create a static library file. The 「bunch of
stuff」 consists of the list of object files supplied as <em>objects</em>, the extra
object files supplied to <a class="reference internal" href="#distutils.ccompiler.CCompiler.add_link_object" title="distutils.ccompiler.CCompiler.add_link_object"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_link_object()</span></code></a> and/or
<a class="reference internal" href="#distutils.ccompiler.CCompiler.set_link_objects" title="distutils.ccompiler.CCompiler.set_link_objects"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_link_objects()</span></code></a>, the libraries supplied to <a class="reference internal" href="#distutils.ccompiler.CCompiler.add_library" title="distutils.ccompiler.CCompiler.add_library"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_library()</span></code></a> and/or
<a class="reference internal" href="#distutils.ccompiler.CCompiler.set_libraries" title="distutils.ccompiler.CCompiler.set_libraries"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_libraries()</span></code></a>, and the libraries supplied as <em>libraries</em> (if any).</p>
<p><em>output_libname</em> should be a library name, not a filename; the filename will be
inferred from the library name. <em>output_dir</em> is the directory where the library
file will be put.</p>
<p><em>debug</em> is a boolean; if true, debugging information will be included in the
library (note that on most platforms, it is the compile step where this matters:
the <em>debug</em> flag is included here just for consistency).</p>
<p><em>target_lang</em> is the target language for which the given objects are being
compiled. This allows specific linkage time treatment of certain languages.</p>
<p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">LibError</span></code> on failure.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.link">
<code class="descname">link</code><span class="sig-paren">(</span><em>target_desc</em>, <em>objects</em>, <em>output_filename</em><span class="optional">[</span>, <em>output_dir=None</em>, <em>libraries=None</em>, <em>library_dirs=None</em>, <em>runtime_library_dirs=None</em>, <em>export_symbols=None</em>, <em>debug=0</em>, <em>extra_preargs=None</em>, <em>extra_postargs=None</em>, <em>build_temp=None</em>, <em>target_lang=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.link" title="本定義的永久連結">¶</a></dt>
<dd><p>Link a bunch of stuff together to create an executable or shared library file.</p>
<p>The 「bunch of stuff」 consists of the list of object files supplied as <em>objects</em>.
<em>output_filename</em> should be a filename. If <em>output_dir</em> is supplied,
<em>output_filename</em> is relative to it (i.e. <em>output_filename</em> can provide
directory components if needed).</p>
<p><em>libraries</em> is a list of libraries to link against. These are library names,
not filenames, since they’re translated into filenames in a platform-specific
way (eg. <em>foo</em> becomes <code class="file docutils literal notranslate"><span class="pre">libfoo.a</span></code> on Unix and <code class="file docutils literal notranslate"><span class="pre">foo.lib</span></code> on
DOS/Windows). However, they can include a directory component, which means the
linker will look in that specific directory rather than searching all the normal
locations.</p>
<p><em>library_dirs</em>, if supplied, should be a list of directories to search for
libraries that were specified as bare library names (ie. no directory
component). These are on top of the system default and those supplied to
<a class="reference internal" href="#distutils.ccompiler.CCompiler.add_library_dir" title="distutils.ccompiler.CCompiler.add_library_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_library_dir()</span></code></a> and/or <a class="reference internal" href="#distutils.ccompiler.CCompiler.set_library_dirs" title="distutils.ccompiler.CCompiler.set_library_dirs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_library_dirs()</span></code></a>. <em>runtime_library_dirs</em>
is a list of directories that will be embedded into the shared library and used
to search for other shared libraries that *it* depends on at run-time. (This
may only be relevant on Unix.)</p>
<p><em>export_symbols</em> is a list of symbols that the shared library will export.
(This appears to be relevant only on Windows.)</p>
<p><em>debug</em> is as for <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compile()</span></code></a> and <a class="reference internal" href="#distutils.ccompiler.CCompiler.create_static_lib" title="distutils.ccompiler.CCompiler.create_static_lib"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_static_lib()</span></code></a>, with the
slight distinction that it actually matters on most platforms (as opposed to
<a class="reference internal" href="#distutils.ccompiler.CCompiler.create_static_lib" title="distutils.ccompiler.CCompiler.create_static_lib"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_static_lib()</span></code></a>, which includes a <em>debug</em> flag mostly for form’s
sake).</p>
<p><em>extra_preargs</em> and <em>extra_postargs</em> are as for <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compile()</span></code></a> (except of
course that they supply command-line arguments for the particular linker being
used).</p>
<p><em>target_lang</em> is the target language for which the given objects are being
compiled. This allows specific linkage time treatment of certain languages.</p>
<p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">LinkError</span></code> on failure.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.link_executable">
<code class="descname">link_executable</code><span class="sig-paren">(</span><em>objects</em>, <em>output_progname</em><span class="optional">[</span>, <em>output_dir=None</em>, <em>libraries=None</em>, <em>library_dirs=None</em>, <em>runtime_library_dirs=None</em>, <em>debug=0</em>, <em>extra_preargs=None</em>, <em>extra_postargs=None</em>, <em>target_lang=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.link_executable" title="本定義的永久連結">¶</a></dt>
<dd><p>Link an executable. <em>output_progname</em> is the name of the file executable, while
<em>objects</em> are a list of object filenames to link in. Other arguments are as for
the <a class="reference internal" href="#distutils.ccompiler.CCompiler.link" title="distutils.ccompiler.CCompiler.link"><code class="xref py py-meth docutils literal notranslate"><span class="pre">link()</span></code></a> method.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.link_shared_lib">
<code class="descname">link_shared_lib</code><span class="sig-paren">(</span><em>objects</em>, <em>output_libname</em><span class="optional">[</span>, <em>output_dir=None</em>, <em>libraries=None</em>, <em>library_dirs=None</em>, <em>runtime_library_dirs=None</em>, <em>export_symbols=None</em>, <em>debug=0</em>, <em>extra_preargs=None</em>, <em>extra_postargs=None</em>, <em>build_temp=None</em>, <em>target_lang=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.link_shared_lib" title="本定義的永久連結">¶</a></dt>
<dd><p>Link a shared library. <em>output_libname</em> is the name of the output library,
while <em>objects</em> is a list of object filenames to link in. Other arguments are
as for the <a class="reference internal" href="#distutils.ccompiler.CCompiler.link" title="distutils.ccompiler.CCompiler.link"><code class="xref py py-meth docutils literal notranslate"><span class="pre">link()</span></code></a> method.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.link_shared_object">
<code class="descname">link_shared_object</code><span class="sig-paren">(</span><em>objects</em>, <em>output_filename</em><span class="optional">[</span>, <em>output_dir=None</em>, <em>libraries=None</em>, <em>library_dirs=None</em>, <em>runtime_library_dirs=None</em>, <em>export_symbols=None</em>, <em>debug=0</em>, <em>extra_preargs=None</em>, <em>extra_postargs=None</em>, <em>build_temp=None</em>, <em>target_lang=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.link_shared_object" title="本定義的永久連結">¶</a></dt>
<dd><p>Link a shared object. <em>output_filename</em> is the name of the shared object that
will be created, while <em>objects</em> is a list of object filenames to link in.
Other arguments are as for the <a class="reference internal" href="#distutils.ccompiler.CCompiler.link" title="distutils.ccompiler.CCompiler.link"><code class="xref py py-meth docutils literal notranslate"><span class="pre">link()</span></code></a> method.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.preprocess">
<code class="descname">preprocess</code><span class="sig-paren">(</span><em>source</em><span class="optional">[</span>, <em>output_file=None</em>, <em>macros=None</em>, <em>include_dirs=None</em>, <em>extra_preargs=None</em>, <em>extra_postargs=None</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.preprocess" title="本定義的永久連結">¶</a></dt>
<dd><p>Preprocess a single C/C++ source file, named in <em>source</em>. Output will be written
to file named <em>output_file</em>, or <em>stdout</em> if <em>output_file</em> not supplied.
<em>macros</em> is a list of macro definitions as for <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compile()</span></code></a>, which will
augment the macros set with <a class="reference internal" href="#distutils.ccompiler.CCompiler.define_macro" title="distutils.ccompiler.CCompiler.define_macro"><code class="xref py py-meth docutils literal notranslate"><span class="pre">define_macro()</span></code></a> and <a class="reference internal" href="#distutils.ccompiler.CCompiler.undefine_macro" title="distutils.ccompiler.CCompiler.undefine_macro"><code class="xref py py-meth docutils literal notranslate"><span class="pre">undefine_macro()</span></code></a>.
<em>include_dirs</em> is a list of directory names that will be added to the default
list, in the same way as <a class="reference internal" href="#distutils.ccompiler.CCompiler.add_include_dir" title="distutils.ccompiler.CCompiler.add_include_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_include_dir()</span></code></a>.</p>
<p>Raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">PreprocessError</span></code> on failure.</p>
</dd></dl>
<p>The following utility methods are defined by the <a class="reference internal" href="#distutils.ccompiler.CCompiler" title="distutils.ccompiler.CCompiler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code></a> class, for
use by the various concrete subclasses.</p>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.executable_filename">
<code class="descname">executable_filename</code><span class="sig-paren">(</span><em>basename</em><span class="optional">[</span>, <em>strip_dir=0</em>, <em>output_dir=''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.executable_filename" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the filename of the executable for the given <em>basename</em>. Typically for
non-Windows platforms this is the same as the basename, while Windows will get
a <code class="file docutils literal notranslate"><span class="pre">.exe</span></code> added.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.library_filename">
<code class="descname">library_filename</code><span class="sig-paren">(</span><em>libname</em><span class="optional">[</span>, <em>lib_type='static'</em>, <em>strip_dir=0</em>, <em>output_dir=''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.library_filename" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the filename for the given library name on the current platform. On Unix
a library with <em>lib_type</em> of <code class="docutils literal notranslate"><span class="pre">'static'</span></code> will typically be of the form
<code class="file docutils literal notranslate"><span class="pre">liblibname.a</span></code>, while a <em>lib_type</em> of <code class="docutils literal notranslate"><span class="pre">'dynamic'</span></code> will be of the form
<code class="file docutils literal notranslate"><span class="pre">liblibname.so</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.object_filenames">
<code class="descname">object_filenames</code><span class="sig-paren">(</span><em>source_filenames</em><span class="optional">[</span>, <em>strip_dir=0</em>, <em>output_dir=''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.object_filenames" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the name of the object files for the given source files.
<em>source_filenames</em> should be a list of filenames.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.shared_object_filename">
<code class="descname">shared_object_filename</code><span class="sig-paren">(</span><em>basename</em><span class="optional">[</span>, <em>strip_dir=0</em>, <em>output_dir=''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.shared_object_filename" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns the name of a shared object file for the given file name <em>basename</em>.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.execute">
<code class="descname">execute</code><span class="sig-paren">(</span><em>func</em>, <em>args</em><span class="optional">[</span>, <em>msg=None</em>, <em>level=1</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.execute" title="本定義的永久連結">¶</a></dt>
<dd><p>Invokes <a class="reference internal" href="#distutils.util.execute" title="distutils.util.execute"><code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.util.execute()</span></code></a>. This method invokes a Python function
<em>func</em> with the given arguments <em>args</em>, after logging and taking into account
the <em>dry_run</em> flag.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.spawn">
<code class="descname">spawn</code><span class="sig-paren">(</span><em>cmd</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.spawn" title="本定義的永久連結">¶</a></dt>
<dd><p>Invokes <code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.util.spawn()</span></code>. This invokes an external process to run
the given command.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.mkpath">
<code class="descname">mkpath</code><span class="sig-paren">(</span><em>name</em><span class="optional">[</span>, <em>mode=511</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.mkpath" title="本定義的永久連結">¶</a></dt>
<dd><p>Invokes <a class="reference internal" href="#distutils.dir_util.mkpath" title="distutils.dir_util.mkpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.dir_util.mkpath()</span></code></a>. This creates a directory and any
missing ancestor directories.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.move_file">
<code class="descname">move_file</code><span class="sig-paren">(</span><em>src</em>, <em>dst</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.move_file" title="本定義的永久連結">¶</a></dt>
<dd><p>Invokes <a class="reference internal" href="#distutils.file_util.move_file" title="distutils.file_util.move_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">distutils.file_util.move_file()</span></code></a>. Renames <em>src</em> to <em>dst</em>.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.announce">
<code class="descname">announce</code><span class="sig-paren">(</span><em>msg</em><span class="optional">[</span>, <em>level=1</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.announce" title="本定義的永久連結">¶</a></dt>
<dd><p>Write a message using <code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.log.debug()</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.warn">
<code class="descname">warn</code><span class="sig-paren">(</span><em>msg</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.warn" title="本定義的永久連結">¶</a></dt>
<dd><p>Write a warning message <em>msg</em> to standard error.</p>
</dd></dl>
<dl class="method">
<dt id="distutils.ccompiler.CCompiler.debug_print">
<code class="descname">debug_print</code><span class="sig-paren">(</span><em>msg</em><span class="sig-paren">)</span><a class="headerlink" href="#distutils.ccompiler.CCompiler.debug_print" title="本定義的永久連結">¶</a></dt>
<dd><p>If the <em>debug</em> flag is set on this <a class="reference internal" href="#distutils.ccompiler.CCompiler" title="distutils.ccompiler.CCompiler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code></a> instance, print <em>msg</em> to
standard output, otherwise do nothing.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-distutils.unixccompiler">
<span id="distutils-unixccompiler-unix-c-compiler"></span><h2>10.3. <a class="reference internal" href="#module-distutils.unixccompiler" title="distutils.unixccompiler: UNIX C Compiler"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.unixccompiler</span></code></a> — Unix C Compiler<a class="headerlink" href="#module-distutils.unixccompiler" title="本標題的永久連結">¶</a></h2>
<p>This module provides the <code class="xref py py-class docutils literal notranslate"><span class="pre">UnixCCompiler</span></code> class, a subclass of
<code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code> that handles the typical Unix-style command-line C compiler:</p>
<ul class="simple">
<li>macros defined with <code class="xref std std-option docutils literal notranslate"><span class="pre">-Dname[=value]</span></code></li>
<li>macros undefined with <code class="xref std std-option docutils literal notranslate"><span class="pre">-Uname</span></code></li>
<li>include search directories specified with <code class="xref std std-option docutils literal notranslate"><span class="pre">-Idir</span></code></li>
<li>libraries specified with <code class="xref std std-option docutils literal notranslate"><span class="pre">-llib</span></code></li>
<li>library search directories specified with <code class="xref std std-option docutils literal notranslate"><span class="pre">-Ldir</span></code></li>
<li>compile handled by <strong class="program">cc</strong> (or similar) executable with <code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code>
option: compiles <code class="file docutils literal notranslate"><span class="pre">.c</span></code> to <code class="file docutils literal notranslate"><span class="pre">.o</span></code></li>
<li>link static library handled by <strong class="program">ar</strong> command (possibly with
<strong class="program">ranlib</strong>)</li>
<li>link shared library handled by <strong class="program">cc</strong> <code class="xref std std-option docutils literal notranslate"><span class="pre">-shared</span></code></li>
</ul>
</div>
<div class="section" id="module-distutils.msvccompiler">
<span id="distutils-msvccompiler-microsoft-compiler"></span><h2>10.4. <a class="reference internal" href="#module-distutils.msvccompiler" title="distutils.msvccompiler: Microsoft Compiler"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.msvccompiler</span></code></a> — Microsoft Compiler<a class="headerlink" href="#module-distutils.msvccompiler" title="本標題的永久連結">¶</a></h2>
<p>This module provides <code class="xref py py-class docutils literal notranslate"><span class="pre">MSVCCompiler</span></code>, an implementation of the abstract
<code class="xref py py-class docutils literal notranslate"><span class="pre">CCompiler</span></code> class for Microsoft Visual Studio. Typically, extension
modules need to be compiled with the same compiler that was used to compile
Python. For Python 2.3 and earlier, the compiler was Visual Studio 6. For Python
2.4 and 2.5, the compiler is Visual Studio .NET 2003.</p>
<p><code class="xref py py-class docutils literal notranslate"><span class="pre">MSVCCompiler</span></code> will normally choose the right compiler, linker etc. on
its own. To override this choice, the environment variables <em>DISTUTILS_USE_SDK</em>
and <em>MSSdk</em> must be both set. <em>MSSdk</em> indicates that the current environment has
been setup by the SDK’s <code class="docutils literal notranslate"><span class="pre">SetEnv.Cmd</span></code> script, or that the environment variables
had been registered when the SDK was installed; <em>DISTUTILS_USE_SDK</em> indicates