Skip to content

Conversation

@scheibel
Copy link
Member

The current symbol visibility is implemented as follows:

  • Symbols are hidden by default (default on Windows; enabled on Linux and macOS with -fvisibility=hidden)
  • Symbols of the public API of a library are tagged using an _API macro
    • for MSVC this translates to dllexport and dllimport declarations with respect to the current compilation state
    • for GCC and clang this macro declares default visibility

Templates are not part of public interface as MSVC can't handle dllexport and dllimport on non-compiled symbols. Thus, we don't define visibility on templates and inline functions on Linux and macOS either and they are hidden by our default setting.

To solve the visibility problem between the compilers MSVC, GCC and clang (considering the platforms Windows, Linux and macOS), I propose the following additional visibility behavior:

  • Differentiate between normal class and function visibility and template visibility
  • Add a specific _TEMPLATE_API macro that resolves to default visibility on GCC and clang but to nothing on MSVC

@scheibel
Copy link
Member Author

Implementation details:

As cmake couldn't help us here, I added two api header templates (one for MSVC and one for GCC and clang) that can be applied using the generate_template_export_header (in addition to the existing generate_export_header macro). The original api header is renamed to an export header and the new api header includes the cmake-generated export header.
Thus, interface compatibility with existing software is achieved.
The provided template handles static library compilation, too by defining the macros as empty.

@scheibel
Copy link
Member Author

I purposely do only define the _TEMPLATE_API. We may add further declarations of the cmake-generated export file when we need them.

@scheibel scheibel changed the title Add explicit visibility for class and function templates (refs #27) Add explicit visibility for class and function templates (refs #56) Apr 13, 2017
@scheibel scheibel changed the title Add explicit visibility for class and function templates (refs #56) Add explicit visibility for class and function templates (closes #56) Apr 13, 2017
@scheibel scheibel merged commit 27db090 into master May 2, 2017
@scheibel scheibel deleted the clang_visibility_fix branch May 2, 2017 15:03
@scheibel scheibel removed the ready label May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants