diff options
| author | Peter0x44 <[email protected]> | 2023-11-28 19:43:45 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-28 20:43:45 +0100 |
| commit | e7a486fa81adac1833253c849ca73c5b3f7ef361 (patch) | |
| tree | 7c2dd970d41272133d35396d888bb388fb717d7e /src | |
| parent | fe53ba80dd684c501eb1c6d297fbf842bb42e515 (diff) | |
| download | raylib-e7a486fa81adac1833253c849ca73c5b3f7ef361.tar.gz raylib-e7a486fa81adac1833253c849ca73c5b3f7ef361.zip | |
Hide unneeded internal symbols when building raylib as an so or dylib (#3573)
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | src/Makefile | 6 | ||||
| -rw-r--r-- | src/raylib.h | 13 | ||||
| -rw-r--r-- | src/raymath.h | 4 | ||||
| -rw-r--r-- | src/rlgl.h | 16 |
5 files changed, 36 insertions, 18 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5092bdf4..4335bda5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,12 +62,10 @@ if (NOT BUILD_SHARED_LIBS) add_library(raylib_static ALIAS raylib) else() MESSAGE(STATUS "Building raylib shared library") - if (WIN32) - target_compile_definitions(raylib - PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED> - INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED> - ) - endif () + target_compile_definitions(raylib + PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED> + INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED> + ) endif() if (${PLATFORM} MATCHES "Web") @@ -84,6 +82,11 @@ if (WITH_PIC OR BUILD_SHARED_LIBS) set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON) endif () +if (BUILD_SHARED_LIBS) + # Hide raylib's symbols by default so RLAPI can expose them + set_property(TARGET raylib PROPERTY C_VISIBILITY_PRESET hidden) +endif () + target_link_libraries(raylib "${LIBS_PRIVATE}") # Sets some compile time definitions for the pre-processor diff --git a/src/Makefile b/src/Makefile index 3ccea903..772e5809 100644 --- a/src/Makefile +++ b/src/Makefile @@ -389,7 +389,13 @@ ifeq ($(RAYLIB_LIBTYPE),SHARED) # BE CAREFUL: It seems that for gcc -fpic is not the same as -fPIC # MinGW32 just doesn't need -fPIC, it shows warnings CFLAGS += -fPIC -DBUILD_LIBTYPE_SHARED + + # hide all symbols by default, so RLAPI can expose them + ifeq ($(PLATFORM_OS),$(filter $(PLATFORM_OS), LINUX BSD OSX)) + CFLAGS += -fvisibility=hidden + endif endif + ifeq ($(PLATFORM),PLATFORM_DRM) # without EGL_NO_X11 eglplatform.h tears Xlib.h in which tears X.h in # which contains a conflicting type Font diff --git a/src/raylib.h b/src/raylib.h index 28f052c7..2bbbef00 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -86,17 +86,22 @@ #define RAYLIB_VERSION_PATCH 0 #define RAYLIB_VERSION "5.1-dev" -// Function specifiers in case library is build/used as a shared library (Windows) +// Function specifiers in case library is build/used as a shared library // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll +// NOTE: visibility("default") attribute makes symbols "visible" when compiled with -fvisibility=hidden #if defined(_WIN32) + #if defined(__TINYC__) + #define __declspec(x) __attribute__((x)) + #endif #if defined(BUILD_LIBTYPE_SHARED) - #if defined(__TINYC__) - #define __declspec(x) __attribute__((x)) - #endif #define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll) #elif defined(USE_LIBTYPE_SHARED) #define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll) #endif +#else + #if defined(BUILD_LIBTYPE_SHARED) + #define RLAPI __attribute__((visibility("default"))) // We are building as a Unix shared library (.so/.dylib) + #endif #endif #ifndef RLAPI diff --git a/src/raymath.h b/src/raymath.h index ff601703..069c9464 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -59,7 +59,9 @@ // Function specifiers definition #if defined(RAYMATH_IMPLEMENTATION) #if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED) - #define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll). + #define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll) + #elif defined(BUILD_LIBTYPE_SHARED) + #define RMAPI __attribute__((visibility("default"))) // We are building raylib as a Unix shared library (.so/.dylib) #elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED) #define RMAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll) #else @@ -109,16 +109,18 @@ #define RLGL_VERSION "4.5" -// Function specifiers in case library is build/used as a shared library (Windows) +// Function specifiers in case library is build/used as a shared library // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll -#if defined(_WIN32) - #if defined(BUILD_LIBTYPE_SHARED) - #define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll) - #elif defined(USE_LIBTYPE_SHARED) - #define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll) - #endif +// NOTE: visibility(default) attribute makes symbols "visible" when compiled with -fvisibility=hidden +#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED) + #define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll) +#elif defined(BUILD_LIBTYPE_SHARED) + #define RLAPI __attribute__((visibility("default"))) // We are building he library as a Unix shared library (.so/.dylib) +#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED) + #define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll) #endif + // Function specifiers definition #ifndef RLAPI #define RLAPI // Functions defined as 'extern' by default (implicit specifiers) |
