Skip to content

Commit bf0fb19

Browse files
committed
Update README.md for new shared library sections
1 parent 94f2408 commit bf0fb19

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ On **Windows** this maps to `__declspec(dllexport)` / `__declspec(dllimport)`.
5656
On **GCC / Clang** both use `__attribute__((visibility("default")))`.
5757
On unrecognized compilers/platforms the attribute expands to nothing.
5858
59+
On GCC / Clang it is strongly recommended to compile the shared library with
60+
`-fvisibility=hidden`. Without it all symbols are public by default, defeating the purpose of
61+
`EXT_API` and leaking internal symbols into the DSO's export table. `EXT_API` then selectively
62+
restores visibility only for the symbols that are meant to be public.
63+
5964
A typical CMake setup looks like:
6065
6166
```cmake
62-
# Shared library target — EXTLIB_IMPL builds the implementation and exports symbols
67+
# Shared library target — EXTLIB_IMPL builds the implementation and exports symbols.
68+
# -fvisibility=hidden ensures only EXT_API-marked symbols are exported on GCC/Clang.
6369
add_library(extlib SHARED extlib_impl.c)
6470
target_compile_definitions(extlib PRIVATE EXTLIB_IMPL EXTLIB_SHARED_EXPORT)
71+
target_compile_options(extlib PRIVATE $<$<C_COMPILER_ID:GNU,Clang,AppleClang>:-fvisibility=hidden>)
6572
6673
# Consumer target — only EXTLIB_SHARED_EXPORT is defined so symbols are imported
6774
target_compile_definitions(my_app PRIVATE EXTLIB_SHARED_EXPORT)

0 commit comments

Comments
 (0)