Skip to content

Commit 660051b

Browse files
committed
Compile modules with with -fvisibility=hidden and expose only init function
1 parent ce157bc commit 660051b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

cmake/Cpp2PyConfig.cmake.in

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ macro(add_cpp2py_module)
8787
add_library(${module_name} MODULE ${wrap_name})
8888
target_link_libraries(${module_name} cpp2py::cpp2py)
8989

90+
# We expose only the modules init function in the dynamic symbol table
91+
target_compile_options(${module_name} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
92+
9093
set_target_properties(${module_name}
9194
PROPERTIES
9295
PREFIX "" #eliminate the lib in front of the module name

cpp2py/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ macro(add_cpp2py_module)
5050
add_library(${module_name} MODULE ${wrap_name})
5151
target_link_libraries(${module_name} cpp2py)
5252

53+
# We expose only the modules init function in the dynamic symbol table
54+
target_compile_options(${module_name} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
55+
5356
set_target_properties(${module_name}
5457
PROPERTIES
5558
PREFIX "" #eliminate the lib in front of the module name

cpp2py/mako/wrap.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ template <typename T> std::function<PyObject *(PyObject *, std::string)> make_py
10771077
#endif
10781078

10791079
//--------------------- module init function -----------------------------
1080-
PyMODINIT_FUNC PyInit_${module.name}(void)
1080+
extern "C" __attribute__((visibility("default"))) PyObject* PyInit_${module.name}(void)
10811081
{
10821082

10831083
#ifdef TRIQS_IMPORTED_CONVERTERS_ARRAYS

0 commit comments

Comments
 (0)