1.3. Controlling dynamic/static linking against LibXC, LibInt2 and BLAS¶
setup.py also compiles C++ code into Python extensions. Some of
these extension are linked against LibXC, LibInt2, BLAS library or a combination
of these. The
setup.py script attempts to detect all of the compiler and
linker settings for these libraries automatically.
For each library, following attempts are made (in the given order) to detect the compiler and linker flags. If the attempt succeeds, i.e. gives a set of satisfactory flags, further steps are not considered for that library.
setup.cfgin the root of the source tree for compilation and link options for that library, as documented in setup.cfg and environment variables. Read in environment variables for compilation and link options for that library.
- Statically link libraries in the
dependsdirectory (for LibXC and LibInt2).
- Use program
pkg-configto get all of the compiler and linker flags for each library. See http://www.freedesktop.org/wiki/Software/pkg-config/ for more details.
setup.*.cfgfile in the directory
data/setup_cfgsthat corresponds to your operating system and CPU architecture for compilation and link options for that library.
- Dynamically link libraries using default library names:
atlas, for LibXC, LibInt2 and BLAS, respectively.
However, if these steps do not result in decent compiler/linker options for some library or the dependencies are not installed, then the compilation will fail and you will get a compiler error message.
The following sections explain how you can override the default guesses of the
setup.cfg and environment variables¶
For each library, a section can be added to the file
setup.cfg to configure
the compiler and linker options. By default, no such file is present in the root
of the source tree, so you have to create a new one. Several examples can be
data/setup_cfgs. For example, this file would compile and link the
extensions on a 64 bit version of Fedora 21:
[libint2] include_dirs=/usr/include/libint2 libraries=int2
This is a setup.cfg file for a compilation with the Intel MKL libraries on Fedora:
[libint2] include_dirs=/usr/include/libint2 libraries=int2 [blas] libraries=mkl_intel_lp64:mkl_core:mkl_sequential:pthread:m
In each section you can define the following variables:
extra_link_args. They correspond to the optional arguments of the
Extension class of the Distutils package, as described here:
The purpose of each keyword is summarized below:
- A list of non-standard directories containing C/C++ header files
- A list of non-standard directories with shared objects (dynamic link
libraries). When any of the
*_LIBRARY_DIRSvariables or the
setup.py build_extare used, keep in mind that at runtime, the dynamic link loader must be informed of these directories. For example, on Linux, the variable
LD_LIBRARY_PATHmust be set accordingly.
- A list of shared objects to link with.
- Extra object files for static linking.
- Extra arguments given to the compiler when compiling source code.
- Extra arguments given to the compiler when linking object files.
Multiple paths or names for one keyword are separated by a colon (
Instead of setting the library configuration in the file
setup.cfg, you may
also set the following environment variables:
1.3.3. Other ways of controlling compilation and linker flags¶
Instead of the library-specific variables above, there are also general methods to configure the compiler and linker.
You may specify a colon-separated list of non-standard directories with
include files in the
CPATH environment variable. For example:
In addition, general compiler and linker flags may be set in the
stage of the installation process. To do so, the installation must be done
in two steps:
./setup.py build_ext EXTRA OPTIONS HERE ./setup.py install --user
./setup.py build_ext --help for a complete list of options. These
options apply to all extensions, so avoid them for static linking.