@@ -73,6 +73,8 @@ For brevity, all code examples assume that the following two lines are present:
7373
7474 Some features may require additional headers, but those will be specified as needed.
7575
76+ .. _simple_example :
77+
7678Creating bindings for a simple function
7779=======================================
7880
@@ -120,23 +122,31 @@ generates binding code that exposes the ``add()`` function to Python.
120122 approach and the used syntax are borrowed from Boost.Python, though the
121123 underlying implementation is very different.
122124
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 `. On Linux and Mac OS, the above
126- example can be compiled using the following command
125+ pybind11 is a header-only library, hence it is not necessary to link against
126+ any special libraries and there are no intermediate (magic) translation steps.
127+ On Linux, the above example can be compiled using the following command:
127128
128129.. code-block :: bash
129130
130- $ c++ -O3 -shared -std=c++11 -I < path-to-pybind11> /include ` python-config --cflags --ldflags` example.cpp -o example.so
131+ $ c++ -O3 -Wall -shared -std=c++11 -fPIC ` python3 -m pybind11 --includes` example.cpp -o example` python3-config --extension-suffix`
132+
133+ For more details on the required compiler flags on Linux and MacOS, see
134+ :ref: `building_manually `. For complete cross-platform compilation instructions,
135+ refer to the :ref: `compiling ` page.
136+
137+ The `python_example `_ and `cmake_example `_ repositories are also a good place
138+ to start. They are both complete project examples with cross-platform build
139+ systems. The only difference between the two is that `python_example `_ uses
140+ Python's ``setuptools `` to build the module, while `cmake_example `_ uses CMake
141+ (which may be preferable for existing C++ projects).
131142
132- In general, it is advisable to include several additional build parameters
133- that can considerably reduce the size of the created binary. Refer to section
134- :ref: `cmake ` for a detailed example of a suitable cross-platform CMake-based
135- build system.
143+ .. _python_example : https://github.com/pybind/python_example
144+ .. _cmake_example : https://github.com/pybind/cmake_example
136145
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.
146+ Building the above C++ code will produce a binary module file that can be
147+ imported to Python. Assuming that the compiled module is located in the
148+ current directory, the following interactive Python session shows how to
149+ load and execute the example:
140150
141151.. code-block :: pycon
142152
0 commit comments