From 1bae5d71753c6f66d1ae08ab545a0da5d70f1b6d Mon Sep 17 00:00:00 2001
From: Olivier BICHLER <olivier.bichler@cea.fr>
Date: Tue, 3 Oct 2023 09:53:07 +0200
Subject: [PATCH] Fixed compile visibility issue

---
 CMakeLists.txt                            | 2 +-
 include/aidge/utils/DynamicAttributes.hpp | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b764086c8..fe353a650 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -68,7 +68,7 @@ target_compile_features(${module_name} PRIVATE cxx_std_14)
 
 target_compile_options(${module_name} PRIVATE
     $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-    -Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow $<$<BOOL:${WERROR}>:-Werror>>)
+    -Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -fvisibility=hidden -Wshadow $<$<BOOL:${WERROR}>:-Werror>>)
 target_compile_options(${module_name} PRIVATE
     $<$<CXX_COMPILER_ID:MSVC>:
     /W4>)
diff --git a/include/aidge/utils/DynamicAttributes.hpp b/include/aidge/utils/DynamicAttributes.hpp
index 37c4104b9..8ee294ce3 100644
--- a/include/aidge/utils/DynamicAttributes.hpp
+++ b/include/aidge/utils/DynamicAttributes.hpp
@@ -183,6 +183,10 @@ private:
 
 #ifdef PYBIND
     // Stores C++ attributes (copy) and Python-only attributes
+    // Code should be compiled with -fvisibility=hidden
+    // See https://pybind11.readthedocs.io/en/stable/faq.html:
+    // “‘SomeClass’ declared with greater visibility than the type of its 
+    // field ‘SomeClass::member’ [-Wattributes]”
     std::map<std::string, py::object> mAttrsPy;
 #endif
 };
-- 
GitLab