Skip to content

Commit 8e2d356

Browse files
committed
Export.h : Implement macros for GCC/Clang
This will allow us to control symbol visibility correctly on Linux and OSX.
1 parent 4fbb0b3 commit 8e2d356

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

include/IECore/Export.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,34 @@
3636
#ifndef IE_CORE_EXPORT_H
3737
#define IE_CORE_EXPORT_H
3838

39-
// define platform-specific macros for importing/exporting symbols
39+
// Define platform-specific macros for importing/exporting symbols
4040
#ifdef _MSC_VER
4141
#define IECORE_IMPORT __declspec(dllimport)
4242
#define IECORE_EXPORT __declspec(dllexport)
4343
#else
44-
#define IECORE_IMPORT
45-
#define IECORE_EXPORT
44+
#define IECORE_IMPORT __attribute__((visibility("default")))
45+
#define IECORE_EXPORT __attribute__((visibility("default")))
4646
#endif
4747

48-
// define IECORE_API macro based on whether or not we are compiling IECore,
49-
// or including headers for linking to it. the IECORE_API macro is the one that is
48+
// When compiling with `-fvisibility=hidden` with GCC or Clang, we run into
49+
// problems when including 3rd party headers that don't define symbol
50+
// visibility. Because they don't explicitly assign default visibility to
51+
// anything, such headers end up inheriting hidden visibility for _everything_.
52+
// This is particularly problematic if we wish to build template classes around
53+
// those 3rd party types, because if they are hidden, GCC will force our
54+
// class to be hidden too, no matter how we declare it. For instance,
55+
// we would be unable to export `TypedData<Imath::V2f>`. We use these macros
56+
// to push/pop default visibility around such problematic includes.
57+
#ifdef __GNUC__
58+
#define IECORE_PUSH_DEFAULT_VISIBILITY _Pragma( "GCC visibility push(default)" )
59+
#define IECORE_POP_DEFAULT_VISIBILITY _Pragma( "GCC visibility pop" )
60+
#else
61+
#define IECORE_PUSH_DEFAULT_VISIBILITY
62+
#define IECORE_POP_DEFAULT_VISIBILITY
63+
#endif
64+
65+
// Define IECORE_API macro based on whether or not we are compiling IECore,
66+
// or including headers for linking to it. The IECORE_API macro is the one that is
5067
// used in the class definitions.
5168
#ifdef IECORE_EXPORTS
5269
#define IECORE_API IECORE_EXPORT

0 commit comments

Comments
 (0)