From a8e7ea7fb026d5d3e0a037f5ced8010187541a41 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Tue, 9 Aug 2016 13:16:26 -0400 Subject: [PATCH 1/2] Set ELF visibility Set symbol visibility to "default" on non-Windows platforms. This allows building with -fvisibility=hidden, which has various advantages, and which some projects will almost certainly want to do. --- tinyxml2.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tinyxml2.h b/tinyxml2.h index fb4376d..2dc98d3 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -72,6 +72,8 @@ distribution. # else # define TINYXML2_LIB # endif +#elif __GNUC__ >= 4 +# define TINYXML2_LIB __attribute__((visibility("default"))) #else # define TINYXML2_LIB #endif From 8170bdc693a34742145491c1588873b8c919c6eb Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Tue, 9 Aug 2016 13:21:06 -0400 Subject: [PATCH 2/2] Build with hidden symbols by default Turn on options to tell CMake to use -fvisibility=hidden by default (on applicable platforms). This has some optimization benefits, and more closely mirrors the Windows behavior of only exporting symbols marked for export, which can help catch errors doing so on non-Windows platforms. This requires CMake 2.8.12 to be effective. (Otherwise, the logic will simply have no effect.) --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1d3ca0..ec2e58f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,9 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") option(BUILD_SHARED_LIBS "build as shared library" ON) option(BUILD_STATIC_LIBS "build as static library" OFF) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) + if(BUILD_SHARED_LIBS) add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h)