diff --git a/cmake/modules/DunePybindxiUtils.cmake b/cmake/modules/DunePybindxiUtils.cmake
index eb92605e0d52b00d9edbebc34b7dd6bbda9cf45c..f37fd344cb64e0d59067c114a67ef415c59cbaf7 100644
--- a/cmake/modules/DunePybindxiUtils.cmake
+++ b/cmake/modules/DunePybindxiUtils.cmake
@@ -113,6 +113,8 @@ function(dune_pybindxi_add_module target_name)
   # namespace; also turning it on for a pybind module compilation here avoids
   # potential warnings or issues from having mixed hidden/non-hidden types.
   set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
+  set_target_properties(${target_name} PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
+
 
   if(WIN32 OR CYGWIN)
     # Link against the Python shared library on Windows
diff --git a/pybind11/tools/FindPythonLibsNew.cmake b/pybind11/tools/FindPythonLibsNew.cmake
index 221bb42e1d9e64eea223e03723ad1f8280eec2d9..5f170c0815940a1f02a212d45b9d258a2dbcc378 100644
--- a/pybind11/tools/FindPythonLibsNew.cmake
+++ b/pybind11/tools/FindPythonLibsNew.cmake
@@ -177,6 +177,7 @@ SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
 dune_register_package_flags(
     INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}
     LIBRARIES ${PYTHON_LIBRARIES}
+    COMPILE_OPTIONS -fvisibility-inlines-hidden -fvisibility=hidden
 )
 
 find_package_message(PYTHON