--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,11 +40,16 @@ set(SRC_LIST
 
 set(BUILD_SHARED_LIBS TRUE CACHE BOOL "Choose if build should be a dynamic or static library")
 if (BUILD_SHARED_LIBS)
+    set(EZC3D_SHARED TRUE)
     add_library(${PROJECT_NAME} SHARED ${SRC_LIST})
 else()
     add_library(${PROJECT_NAME} STATIC ${SRC_LIST})
 endif()
-set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_debug")
+set_target_properties(${PROJECT_NAME} PROPERTIES
+    DEBUG_POSTFIX "_debug"
+    CXX_VISIBILITY_PRESET hidden
+    VISIBILITY_INLINES_HIDDEN ON
+)
 
 # Remember the CMAKE_CURRENT_BINARY_DIR (important if ezc3d is used as submodule)
 set(EZC3D_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
--- a/include/ezc3dConfig.h.in
+++ b/include/ezc3dConfig.h.in
@@ -1,12 +1,18 @@
 #ifndef EZC3D_CONFIG_H
 #define EZC3D_CONFIG_H
 
+#cmakedefine EZC3D_SHARED
+
 // dllexport/import declaration
-#ifdef _WIN32
-    #ifdef EZC3D_API_EXPORTS
-        #define EZC3D_API __declspec(dllexport)
+#ifdef EZC3D_SHARED
+    #ifdef _WIN32
+        #ifdef EZC3D_API_EXPORTS
+            #define EZC3D_API __declspec(dllexport)
+        #else
+            #define EZC3D_API __declspec(dllimport)
+        #endif
     #else
-        #define EZC3D_API __declspec(dllimport)
+        #define EZC3D_API __attribute__ ((visibility ("default")))
     #endif
 #else
     #define EZC3D_API
