From 0edf26d84f9f1cd9b4eb36edbb179ae6b94f0ff0 Mon Sep 17 00:00:00 2001 From: Yikai Zhao Date: Wed, 15 Dec 2021 00:02:02 +0800 Subject: [PATCH] Do not export unnecessary symbols in dynamic library --- CMakeLists.txt | 1 + vterm-module.h | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af4f2d5a..e766884d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ endif() add_library(vterm-module MODULE vterm-module.c utf8.c elisp.c) set_target_properties(vterm-module PROPERTIES C_STANDARD 99 + C_VISIBILITY_PRESET "hidden" POSITION_INDEPENDENT_CODE ON PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR} diff --git a/vterm-module.h b/vterm-module.h index 5cb1f6d6..96f538f6 100644 --- a/vterm-module.h +++ b/vterm-module.h @@ -6,7 +6,22 @@ #include #include -int plugin_is_GPL_compatible; +// https://gcc.gnu.org/wiki/Visibility +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define VTERM_EXPORT __attribute__ ((dllexport)) + #else + #define VTERM_EXPORT __declspec(dllexport) + #endif +#else + #if __GNUC__ >= 4 + #define VTERM_EXPORT __attribute__ ((visibility ("default"))) + #else + #define VTERM_EXPORT + #endif +#endif + +VTERM_EXPORT int plugin_is_GPL_compatible; #define SB_MAX 100000 // Maximum 'scrollback' value. @@ -147,6 +162,6 @@ emacs_value Fvterm_get_prompt_point(emacs_env *env, ptrdiff_t nargs, emacs_value Fvterm_reset_cursor_point(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data); -int emacs_module_init(struct emacs_runtime *ert); +VTERM_EXPORT int emacs_module_init(struct emacs_runtime *ert); #endif /* VTERM_MODULE_H */