@@ -122,21 +122,45 @@ generates binding code that exposes the ``add()`` function to Python.
122122
123123pybind11 is a header-only-library, hence it is not necessary to link against
124124any special libraries (other than Python itself). On Windows, use the CMake
125- build file discussed in section :ref: `cmake `. On Linux and Mac OS, the above
126- example can be compiled using the following command
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:
127152
128153.. code-block :: bash
129154
130- $ c++ -O3 -shared -std=c++11 -I < path-to-pybind 11> /include ` python -config --cflags --ldflags ` example.cpp -o example.so
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 `
131156
132157 In general, it is advisable to include several additional build parameters
133158that can considerably reduce the size of the created binary. Refer to section
134159:ref: `cmake ` for a detailed example of a suitable cross-platform CMake-based
135160build system.
136161
137- Assuming that the created file :file: `example.so ` (:file: `example.pyd ` on Windows)
138- is located in the current directory, the following interactive Python session
139- shows how to load and execute the example.
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.
140164
141165.. code-block :: pycon
142166
0 commit comments