From d506b8a5ed6d499129ed6f3e4e453ab3f70e9795 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Fri, 17 Sep 2021 17:51:49 +0200 Subject: [PATCH] feat: hide non-exported symbols on Unix --- src/CMakeLists.txt | 3 +++ src/include/lean/lean.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e84126ad8f..6391982b27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -308,6 +308,9 @@ endif() if(NOT(${CMAKE_SYSTEM_NAME} MATCHES "Windows")) # export symbols for the interpreter (done via `LEAN_EXPORT` for Windows) set(LEAN_DYN_EXE_LINKER_FLAGS "${LEAN_DYN_EXE_LINKER_FLAGS} -rdynamic") + # hide all other symbols + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") + set(LEANC_EXTRA_FLAGS "${LEANC_EXTRA_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") endif() # On Windows, add bcrypt for random number generation diff --git a/src/include/lean/lean.h b/src/include/lean/lean.h index cc76e4791f..081726de6c 100644 --- a/src/include/lean/lean.h +++ b/src/include/lean/lean.h @@ -49,7 +49,7 @@ extern "C" { #ifdef _WIN32 #define LEAN_EXPORT __declspec(dllexport) #else -#define LEAN_EXPORT +#define LEAN_EXPORT __attribute__((visibility("default"))) #endif // We set `LEAN_EXPORTING` when compiling objects of libleanshared, but not when including this header in any other context.