Skip to content

Commit 368fb7f

Browse files
committed
Update docs to reflect forced hidden visibility
1 parent 88ae0c1 commit 368fb7f

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

docs/advanced/misc.rst

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,16 @@ has been executed:
135135
136136
Naturally, both methods will fail when there are cyclic dependencies.
137137

138-
Note that compiling code which has its default symbol visibility set to
139-
*hidden* (e.g. via the command line flag ``-fvisibility=hidden`` on GCC/Clang) can interfere with the
140-
ability to access types defined in another extension module. Workarounds
141-
include changing the global symbol visibility (not recommended, because it will
142-
lead unnecessarily large binaries) or manually exporting types that are
143-
accessed by multiple extension modules:
138+
Note that pybind11 code compiled with hidden-by-default symbol visibility (e.g.
139+
via the command line flag ``-fvisibility=hidden`` on GCC/Clang), which is
140+
strongly recommended for pybind11 modules, can interfere with the ability to
141+
access types defined in another extension module. Working around this requires
142+
manually export types that are accessed by multiple extension modules; pybind11
143+
provides a macro to do just this:
144144

145145
.. code-block:: cpp
146146
147-
#ifdef _WIN32
148-
# define EXPORT_TYPE __declspec(dllexport)
149-
#else
150-
# define EXPORT_TYPE __attribute__ ((visibility("default")))
151-
#endif
152-
153-
class EXPORT_TYPE Dog : public Animal {
147+
class PYBIND11_EXPORT Dog : public Animal {
154148
...
155149
};
156150

docs/compiling.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ removes this target from the default build (see CMake docs for details).
7474

7575
Since pybind11 is a template library, ``pybind11_add_module`` adds compiler
7676
flags to ensure high quality code generation without bloat arising from long
77-
symbol names and duplication of code in different translation units. The
78-
additional flags enable LTO (Link Time Optimization), set default visibility
79-
to *hidden* and strip unneeded symbols. See the :ref:`FAQ entry <faq:symhidden>`
80-
for a more detailed explanation. These optimizations are never applied in
81-
``Debug`` mode. If ``NO_EXTRAS`` is given, they will always be disabled, even
82-
in ``Release`` mode. However, this will result in code bloat and is generally
83-
not recommended.
77+
symbol names and duplication of code in different translation units. It
78+
sets default visibility to *hidden*, which is required for some pybind11
79+
features and functionality when attempting to load multiple pybind11 modules
80+
compiled under different pybind11 versions. It also adds additional flags
81+
enabling LTO (Link Time Optimization) and strip unneeded symbols. See the
82+
:ref:`FAQ entry <faq:symhidden>` for a more detailed explanation. These
83+
latter optimizations are never applied in ``Debug`` mode. If ``NO_EXTRAS`` is
84+
given, they will always be disabled, even in ``Release`` mode. However, this
85+
will result in code bloat and is generally not recommended.
8486

8587
As stated above, LTO is enabled by default. Some newer compilers also support
8688
different flavors of LTO such as `ThinLTO`_. Setting ``THIN_LTO`` will cause
@@ -181,9 +183,8 @@ to an independently constructed (through ``add_library``, not
181183
flags (i.e. this is up to you).
182184

183185
These include Link Time Optimization (``-flto`` on GCC/Clang/ICPC, ``/GL``
184-
and ``/LTCG`` on Visual Studio). Default-hidden symbols on GCC/Clang/ICPC
185-
(``-fvisibility=hidden``) and .OBJ files with many sections on Visual Studio
186-
(``/bigobj``). The :ref:`FAQ <faq:symhidden>` contains an
186+
and ``/LTCG`` on Visual Studio) and .OBJ files with many sections on Visual
187+
Studio (``/bigobj``). The :ref:`FAQ <faq:symhidden>` contains an
187188
explanation on why these are needed.
188189

189190
Embedding the Python interpreter

0 commit comments

Comments
 (0)