Skip to content

Commit 48ffa27

Browse files
committed
Docs: move build notes to build section, update w/ #921
1 parent 77d2354 commit 48ffa27

File tree

2 files changed

+36
-41
lines changed

2 files changed

+36
-41
lines changed

docs/basics.rst

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -120,47 +120,10 @@ generates binding code that exposes the ``add()`` function to Python.
120120
approach and the used syntax are borrowed from Boost.Python, though the
121121
underlying implementation is very different.
122122

123-
pybind11 is a header-only-library, hence it is not necessary to link against
124-
any special libraries (other than Python itself). On Windows, use the CMake
125-
build file discussed in section :ref:`cmake`.
126-
127-
On Linux, the above example can be compiled using the following command:
128-
129-
.. code-block:: bash
130-
131-
$ c++ -O3 -Wall -shared -std=c++11 -fPIC -I$PYBIND11_INCLUDE `python3-config --includes` example.cpp -o example`python3-config --extension-suffix`
132-
133-
where ``PYBIND11_INCLUDE`` is the path to the include folder of pybind11.
134-
If pybind11 installed as a Python package, it can be obtained as follows:
135-
136-
.. code-block:: bash
137-
138-
$ PYBIND11_INCLUDE=`python -c 'import pybind11; print(pybind11.get_include())'`
139-
140-
Note that for some Python distributions the list of Python's system include
141-
folders contains the one where pybind11 gets installed, in which case
142-
passing ``-I$PYBIND11_INCLUDE`` is optional.
143-
144-
On Python 2.7.x: ``python-config`` has to be used instead of ``python3-config``
145-
in the command above. Besides, ``--extension-suffix`` option may or may not
146-
be available, depending on the distribution; in the latter case, the module
147-
extension can be manually set to ``.so``.
148-
149-
On Mac OS: the build command is almost the same but it also requires passing
150-
the ``-undefined dynamic_lookup`` flag so as to ignore missing symbols when
151-
building the module:
152-
153-
.. code-block:: bash
154-
155-
$ c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup -I$PYBIND11_INCLUDE `python3-config --includes` example.cpp -o example`python3-config --extension-suffix`
156-
157-
In general, it is advisable to include several additional build parameters
158-
that can considerably reduce the size of the created binary. Refer to section
159-
:ref:`cmake` for a detailed example of a suitable cross-platform CMake-based
160-
build system.
161-
162-
Assuming that the compiled module is located in the current directory, the
163-
following interactive Python session shows how to load and execute the example.
123+
Building the above C++ code (refer to :ref:`compiling` for details) will produce
124+
a binary module file that can be imported to Python. Assuming that the compiled
125+
module is located in the current directory, the following interactive Python
126+
session shows how to load and execute the example:
164127

165128
.. code-block:: pycon
166129

docs/compiling.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
1+
.. _compiling:
2+
13
Build systems
24
#############
35

6+
Building manually
7+
=================
8+
9+
pybind11 is a header-only-library, hence it is not necessary to link against
10+
any special libraries (other than Python itself).
11+
12+
On Linux, the above example can be compiled using the following command:
13+
14+
.. code-block:: bash
15+
16+
$ c++ -O3 -Wall -shared -std=c++11 -fPIC `python -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`
17+
18+
Note that on Python 2.7.x ``python-config`` has to be used instead of
19+
``python3-config`` in the command above. Besides, ``--extension-suffix``
20+
option may or may not be available, depending on the distribution; in the latter
21+
case, the module extension can be manually set to ``.so``.
22+
23+
On Mac OS: the build command is almost the same but it also requires passing
24+
the ``-undefined dynamic_lookup`` flag so as to ignore missing symbols when
25+
building the module:
26+
27+
.. code-block:: bash
28+
29+
$ c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`
30+
31+
In general, it is advisable to include several additional build parameters
32+
that can considerably reduce the size of the created binary. Refer to section
33+
:ref:`cmake` for a detailed example of a suitable cross-platform CMake-based
34+
build system that works on all platforms including Windows.
35+
436
Building with setuptools
537
========================
638

0 commit comments

Comments
 (0)