EnTT  2.7.3
docs/shared.md
1 ### EnTT and shared libraries
2 
3 To make sure that an application and a shared library that use both `EnTT` can
4 interact correctly when symbols are hidden by default, there are some tricks to
5 follow.<br/>
6 In particular and in order to avoid undefined behaviors, all the instantiation
7 of the `Family` class template shall be made explicit along with the system-wide
8 specifier to use to export them.
9 
10 At the time I'm writing this document, the classes that use internally the above
11 mentioned class template are `Dispatcher`, `Emitter` and `Registry`. Therefore
12 and as an example, if you use the `Registry` class template in your shared
13 library and want to set symbols visibility to _hidden_ by default, the following
14 lines are required to allow it to function properly with a client that also uses
15 the `Registry` somehow:
16 
17 * On GNU/Linux:
18 
19  ```cpp
20  namespace entt {
21  template class __attribute__((visibility("default"))) Family<struct InternalRegistryTagFamily>;
22  template class __attribute__((visibility("default"))) Family<struct InternalRegistryComponentFamily>;
23  template class __attribute__((visibility("default"))) Family<struct InternalRegistryHandlerFamily>;
24  }
25  ```
26 
27 * On Windows:
28 
29  ```cpp
30  namespace entt {
31  template class __declspec(dllexport) Family<struct InternalRegistryTagFamily>;
32  template class __declspec(dllexport) Family<struct InternalRegistryComponentFamily>;
33  template class __declspec(dllexport) Family<struct InternalRegistryHandlerFamily>;
34  }
35  ```
36 
37 Otherwise, the risk is that type identifiers are different between the shared
38 library and the application and this will prevent the whole thing from
39 functioning correctly for obvious reasons.