|
Original |
Translation |
|
187
|
Compiling a Python extension written in C or C++ will sometimes require specifying custom flags for the compiler and linker in order to use a particular library or produce a special kind of object code. This is especially true if the extension hasn't been tested on your platform, or if you're trying to cross-compile Python.
|
|
|
188
|
In the most general case, the extension author might have foreseen that compiling the extensions would be complicated, and provided a :file:`Setup` file for you to edit. This will likely only be done if the module distribution contains many separate extension modules, or if they often require elaborate sets of compiler flags in order to work.
|
|
|
189
|
A :file:`Setup` file, if present, is parsed in order to get a list of extensions to build. Each line in a :file:`Setup` describes a single module. Lines have the following structure::
|
|
|
190
|
module ... [sourcefile ...] [cpparg ...] [library ...]
|
|
|
191
|
|
192
|
*module* is the name of the extension module to be built, and should be a valid Python identifier. You can't just change this in order to rename a module (edits to the source code would also be needed), so this should be left alone.
|
|
|
193
|
*sourcefile* is anything that's likely to be a source code file, at least judging by the filename. Filenames ending in :file:`.c` are assumed to be written in C, filenames ending in :file:`.C`, :file:`.cc`, and :file:`.c++` are assumed to be C++, and filenames ending in :file:`.m` or :file:`.mm` are assumed to be in Objective C.
|
|
|
194
|
*cpparg* is an argument for the C preprocessor, and is anything starting with :option:`-I`, :option:`-D`, :option:`-U` or :option:`-C`.
|
|
|
195
|
*library* is anything ending in :file:`.a` or beginning with :option:`-l` or :option:`-L`.
|
|
|
196
|
If a particular platform requires a special library on your platform, you can add it by editing the :file:`Setup` file and running ``python setup.py build``. For example, if the module defined by the line ::
|
|