Skip to content

Commit 7ae9031

Browse files
committed
Properly set up visibility for static builds.
Should finally fix the dreaded Clang linker warning on macOS.
1 parent 7ce0212 commit 7ae9031

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

doc/corrade-changelog.dox

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ namespace Corrade {
142142
for more information when using custom buildsystems, see also
143143
[mosra/corrade#51](https://github.com/mosra/corrade/issues/51).
144144
- Fixed compilation with Clang and `-std=gnu++14` (see [mosra/corrade#62](https://github.com/mosra/corrade/pull/62)
145+
- @ref CORRADE_VISIBILITY_STATIC no longer exports symbols in static
146+
libraries to be consistent with hidden visibility by default, additionally
147+
`-fvisibility-inlines-hidden` is passed along with `-fvisibility=hidden`
148+
when @ref corrade-cmake "CORRADE_USE_PEDANTIC_FLAGS" property is enabled in
149+
CMake on GCC and Clang to avoid linker warnings on macOS (see
150+
[mosra/corrade#53](https://github.com/mosra/corrade/issues/53))
145151

146152
@subsection corrade-changelog-latest-bugfixes Bug fixes
147153

modules/UseCorrade.cmake

+7-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "(Appl
7373
"-Werror=return-type"
7474
"-Wmissing-declarations"
7575
"-pedantic"
76-
"-fvisibility=hidden")
76+
# Needs to have both, otherwise Clang's linker on macOS complains that
77+
# "direct access in function [...] to global weak symbol [...] means the
78+
# weak symbol cannot be overridden at runtime. This was likely caused
79+
# by different translation units being compiled with different
80+
# visibility settings." See also various google results for the above
81+
# message.
82+
"-fvisibility=hidden" "-fvisibility-inlines-hidden")
7783

7884
# Some flags are not yet supported everywhere
7985
# TODO: do this with check_c_compiler_flags()

src/Corrade/Utility/VisibilityMacros.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@
5050
#endif
5151

5252
/** @hideinitializer
53-
* @brief Public symbol in a static library
54-
*/
55-
#ifdef CORRADE_TARGET_WINDOWS
53+
@brief Public symbol in a static library
54+
55+
Defined as empty --- to be consistent with hidden visibility by default,
56+
symbols in static libraries shouldn't be exported either.
57+
*/
5658
#define CORRADE_VISIBILITY_STATIC
57-
#else
58-
#define CORRADE_VISIBILITY_STATIC __attribute__ ((visibility ("default")))
59-
#endif
6059

6160
/** @hideinitializer
6261
@brief Local symbol

0 commit comments

Comments
 (0)