Remove obsolete example reference (#457)

* Remove obsolete example reference
* Make example fully-working (except for #includes)

Fixes #456.
This commit is contained in:
Jason Rhinelander 2016-10-22 12:54:33 -04:00 committed by Wenzel Jakob
parent 18e9590ca9
commit fb7c9fd326

View File

@ -93,8 +93,10 @@ and the binding code
How can I reduce the build time? How can I reduce the build time?
================================ ================================
It's good practice to split binding code over multiple files, as is done in It's good practice to split binding code over multiple files, as in the
the included file :file:`example/example.cpp`. following example:
:file:`example.cpp`:
.. code-block:: cpp .. code-block:: cpp
@ -107,14 +109,41 @@ the included file :file:`example/example.cpp`.
init_ex1(m); init_ex1(m);
init_ex2(m); init_ex2(m);
/* ... */ /* ... */
return m.ptr(); return m.ptr();
} }
The various ``init_ex`` functions should be contained in separate files that :file:`ex1.cpp`:
can be compiled independently from another. Following this approach will
.. code-block:: cpp
void init_ex1(py::module &m) {
m.def("add", [](int a, int b) { return a + b; });
}
:file:`ex2.cpp`:
.. code-block:: cpp
void init_ex1(py::module &m) {
m.def("sub", [](int a, int b) { return a - b; });
}
:command:`python`:
.. code-block:: pycon
>>> import example
>>> example.add(1, 2)
3
>>> example.sub(1, 1)
0
As shown above, the various ``init_ex`` functions should be contained in
separate files that can be compiled independently from one another, and then
linked together into the same final shared object. Following this approach
will:
1. reduce memory requirements per compilation unit. 1. reduce memory requirements per compilation unit.