@@ -151,6 +151,33 @@ specifying a larger value, e.g. ``-ftemplate-depth=1024`` on GCC/Clang. The
151151culprit is generally the generation of function signatures at compile time
152152using C++14 template metaprogramming.
153153
154+ .. _`faq:hidden_visibility` :
155+
156+ "‘SomeClass’ declared with greater visibility than the type of its field ‘SomeClass::member’ [-Wattributes]"
157+ ============================================================================================================
158+
159+ This error typically indicates that you are compiling without the required
160+ ``-fvisibility `` flag. pybind11 code internally forces hidden visibility on
161+ all internal code, but if non-hidden (and thus *exported *) code attempts to
162+ include a pybind type (for example, ``py::object `` or ``py::list ``) you can run
163+ into this warning.
164+
165+ To avoid it, make sure you are specifying ``-fvisibility=hidden `` when
166+ compiling pybind code.
167+
168+ As to why ``-fvisibility=hidden `` is necessary, because pybind modules could
169+ have been compiled under different versions of pybind itself, it is also
170+ important that the symbols defined in one module do not clash with the
171+ potentially-incompatible symbols defined in another. While Python extension
172+ modules are usually loaded with localized symbols (under POSIX systems
173+ typically using ``dlopen `` with the ``RTLD_LOCAL `` flag), this Python default
174+ can be changed, but even if it isn't it is not always enough to guarantee
175+ complete independence of the symbols involved when not using
176+ ``-fvisibility=hidden ``.
177+
178+ Additionally, ``-fvisiblity=hidden `` can deliver considerably binary size
179+ savings. (See the following section for more details).
180+
154181
155182.. _`faq:symhidden` :
156183
@@ -192,11 +219,14 @@ world. So we'll generally only want to export symbols for those functions which
192219are actually called from the outside.
193220
194221This can be achieved by specifying the parameter ``-fvisibility=hidden `` to GCC
195- and Clang, which sets the default symbol visibility to *hidden *. It's best to
196- do this only for release builds, since the symbol names can be helpful in
197- debugging sessions. On Visual Studio, symbols are already hidden by default, so
198- nothing needs to be done there. Needless to say, this has a tremendous impact
199- on the final binary size of the resulting extension library.
222+ and Clang, which sets the default symbol visibility to *hidden *, which has a
223+ tremendous impact on the final binary size of the resulting extension library.
224+ (On Visual Studio, symbols are already hidden by default, so nothing needs to
225+ be done there.)
226+
227+ In addition to decreasing binary size, ``-fvisibility=hidden `` also avoids
228+ potential serious issues when loading multiple modules and is required for
229+ proper pybind operation. See the previous FAQ entry for more details.
200230
201231Another aspect that can require a fair bit of code are function signature
202232descriptions. pybind11 automatically generates human-readable function
0 commit comments