how-to-export-cpp-library icon indicating copy to clipboard operation
how-to-export-cpp-library copied to clipboard

Prefer GenerateExportHeader to EXPORT_ALL_SYMBOLS

Open mathstuf opened this issue 6 years ago • 1 comments
trafficstars

In my experience, having finer control over exported symbols is much better than exporting all of them (either via the default behavior of GCC-and-friends or via WINDOWS_EXPORT_ALL_SYMBOLS). Among these benefits:

  • smaller binary size (internal template instantiation names can be hidden)
  • better inlining; if the compiler/LTO knows a symbol isn't exposed at all, it can be more aggressively inlined)
  • less chance of someone using a symbol you didn't intend to expose (more a problem in C than C++)

Instead, GenerateExportHeader should be used to generate a header with _EXPORT macros to decorate classes, functions, and variables as being available to other libraries.

mathstuf avatar Oct 26 '19 19:10 mathstuf

:+1: Unfortunately we are dealing with lazy researchers who ignore this kind of issues, therefore EXPORT_ALL_SYMBOLS is the quick and dirty way to achieve the same result. :stuck_out_tongue_closed_eyes:

drdanz avatar Oct 29 '19 14:10 drdanz