It is important to building with -fvisibility=hidden to hide the symbols. Quote from issue 665.
Importance of builiding with hidden visibility is well described in GCC Wiki here.
tldr: It allows compiler and linker to do more optimizations, makes startup faster and binaries smaller.
In addition, there are other requirements, such as
- Minimization of the set of exported symbols in order to track ABI changes
- compliance
To this end, support for -fvisibility=hidden has been implemented and tested in our internal build. Although we have done our best to minimize changes, there are still 366 changed files with 503 additions and 480 deletions. However, the core code is simple, and I’ll post it here for discussion(excerpt).
+++ b/build_scripts/build_usd.py
+# Hide symbols
+HIDDEN_SYMBOLS = ['-DCMAKE_CXX_VISIBILITY_PRESET=hidden',
+ '-DCMAKE_C_VISIBILITY_PRESET=hidden',
+ '-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON']
+
@@ -1801,6 +1806,8 @@ def InstallUSD(context, force, buildArgs):
...
extraArgs.append('-DBoost_NO_SYSTEM_PATHS=True')
+
+ extraArgs += HIDDEN_SYMBOLS
+++ pxr/base/arch/export.h
#if defined(ARCH_OS_WINDOWS)
+# define ARCH_EXPORT_TYPE
#elif defined(ARCH_COMPILER_GCC) && ARCH_COMPILER_GCC_MAJOR >= 4 || defined(ARCH_COMPILER_CLANG)
+# define ARCH_EXPORT_TYPE __attribute__((visibility("default")))
And many changes like this
+++ b/pxr/base/gf/camera.h
@@ -29,7 +29,7 @@ class GfFrustum;
/// This class provides a thin wrapper on the camera data model,
/// with a small number of computations.
///
-class GfCamera
+class ARCH_EXPORT_TYPE GfCamera
If anyone is interested, I’ll prepare a PR.