Python bindings broken with pybind11 version 2.7.0
Python bindings are broken with the latest pybind11 version 2.7.0 released today.
AFAICT, there are at least two kinds of problems. Here is what I understood. I don't know how to solve them properly.
- First, many tests are failing with
Uncaught exception std::runtime_error: pybind11::object_api<>::operator() PyGILState_Check() failure.
The culprit seems to be commit https://github.com/pybind/pybind11/commit/ad6bf5cd39ca64b4a9bf846b84b11c4c8df1c8e1 and an obvious workaround is then to defineNDEBUG
before including <pybind11/pybind11.h>. For example:
--- a/src/bindings/python/simgrid_python.cpp
+++ b/src/bindings/python/simgrid_python.cpp
@@ -13,6 +13,12 @@
#pragma GCC diagnostic ignored "-Wunused-value"
#endif
+#ifndef NDEBUG
+#define NDEBUG
+#include <pybind11/pybind11.h>
+#undef NDEBUG
+#endif
+
#include <pybind11/functional.h>
#include <pybind11/pybind11.h> // Must come before our own stuff
#include <pybind11/stl.h>
- The second problem is at build time, specific to Win32, and can be seen e.g. on Appveyor (https://ci.appveyor.com/project/mquinson/simgrid/builds/40020776 ).
The offending commit seems to be https://github.com/pybind/pybind11/commit/3ac690b88be00a44c1988afc209a395d87a57051 but I don't know any workaround.
Sample error message:
In file included from C:/projects/simgrid/pybind11/include/pybind11/pytypes.h:12,
from C:/projects/simgrid/pybind11/include/pybind11/cast.h:13,
from C:/projects/simgrid/pybind11/include/pybind11/attr.h:13,
from C:/projects/simgrid/pybind11/include/pybind11/pybind11.h:44,
from C:/projects/simgrid/pybind11/include/pybind11/functional.h:12,
from C:\projects\simgrid\src\bindings\python\simgrid_python.cpp:16:
C:/projects/simgrid/pybind11/include/pybind11/detail/common.h:735:23: error: 'dllexport' implies default visibility, but 'class pybind11::builtin_exception' has already been declared with a different visibility
class PYBIND11_EXPORT builtin_exception : public std::runtime_error {
^~~~~~~~~~~~~~~~~