Skip to content

Commit

Permalink
Properly set up visibility for static builds.
Browse files Browse the repository at this point in the history
Should finally fix the dreaded Clang linker warning on macOS.
  • Loading branch information
mosra committed Jun 16, 2019
1 parent 7ce0212 commit 7ae9031
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions doc/corrade-changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ namespace Corrade {
for more information when using custom buildsystems, see also
[mosra/corrade#51](https://github.com/mosra/corrade/issues/51).
- Fixed compilation with Clang and `-std=gnu++14` (see [mosra/corrade#62](https://github.com/mosra/corrade/pull/62)
- @ref CORRADE_VISIBILITY_STATIC no longer exports symbols in static
libraries to be consistent with hidden visibility by default, additionally
`-fvisibility-inlines-hidden` is passed along with `-fvisibility=hidden`
when @ref corrade-cmake "CORRADE_USE_PEDANTIC_FLAGS" property is enabled in
CMake on GCC and Clang to avoid linker warnings on macOS (see
[mosra/corrade#53](https://github.com/mosra/corrade/issues/53))

@subsection corrade-changelog-latest-bugfixes Bug fixes

Expand Down
8 changes: 7 additions & 1 deletion modules/UseCorrade.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "(Appl
"-Werror=return-type"
"-Wmissing-declarations"
"-pedantic"
"-fvisibility=hidden")
# Needs to have both, otherwise Clang's linker on macOS complains that
# "direct access in function [...] to global weak symbol [...] means the
# weak symbol cannot be overridden at runtime. This was likely caused
# by different translation units being compiled with different
# visibility settings." See also various google results for the above
# message.
"-fvisibility=hidden" "-fvisibility-inlines-hidden")

# Some flags are not yet supported everywhere
# TODO: do this with check_c_compiler_flags()
Expand Down
11 changes: 5 additions & 6 deletions src/Corrade/Utility/VisibilityMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@
#endif

/** @hideinitializer
* @brief Public symbol in a static library
*/
#ifdef CORRADE_TARGET_WINDOWS
@brief Public symbol in a static library
Defined as empty --- to be consistent with hidden visibility by default,
symbols in static libraries shouldn't be exported either.
*/
#define CORRADE_VISIBILITY_STATIC
#else
#define CORRADE_VISIBILITY_STATIC __attribute__ ((visibility ("default")))
#endif

/** @hideinitializer
@brief Local symbol
Expand Down

0 comments on commit 7ae9031

Please sign in to comment.