HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
export.h
Go to the documentation of this file.
1 // Copyright 2008-present Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
4 
5 
6 #pragma once
7 
8 
9 /// \file
10 /// Macros necessary for proper symbol export from dynamic libraries.
11 
12 
13 ///
14 /// On Windows, when compiling code that will end up in a DLL, symbols
15 /// must be marked as 'exported' (i.e. __declspec(dllexport)) or they
16 /// won't be visible to programs linking against the DLL.
17 ///
18 /// In addition, when compiling the application code that calls the DLL,
19 /// if a routine is marked as 'imported' (i.e. __declspec(dllimport)),
20 /// the compiler can be smart about eliminating a level of calling
21 /// indirection. But you DON'T want to use __declspec(dllimport) when
22 /// calling a function from within its own DLL (it will still compile
23 /// correctly, just not with maximal efficiency). Which is quite the
24 /// dilemma since the same header file is used by both the library and
25 /// its clients. Sheesh!
26 ///
27 /// But on Linux/OSX as well, we want to only have the DSO export the
28 /// symbols we designate as the public interface. So we link with
29 /// -fvisibility=hidden to default to hiding the symbols. See
30 /// http://gcc.gnu.org/wiki/Visibility
31 ///
32 /// We solve this awful mess by defining these macros:
33 ///
34 /// OIIO_API - used for the OpenImageIO public API. Normally, assumes
35 /// that it's being seen by a client of the library, and
36 /// therefore declare as 'imported'. But if
37 /// OpenImageIO_EXPORT is defined (as is done by CMake
38 /// when compiling the library itself), change the
39 /// declaration to 'exported'.
40 /// OIIO_EXPORT - explicitly exports a symbol that isn't part of the
41 /// public API but still needs to be visible.
42 /// OIIO_LOCAL - explicitly hides a symbol that might otherwise be
43 /// exported
44 ///
45 ///
46 
47 #if defined(_WIN32) || defined(__CYGWIN__)
48 # ifdef OIIO_STATIC_DEFINE
49 # define OIIO_IMPORT
50 # define OIIO_EXPORT
51 # else
52 # define OIIO_IMPORT __declspec(dllimport)
53 # define OIIO_EXPORT __declspec(dllexport)
54 # endif
55 # define OIIO_LOCAL
56 #else
57 # define OIIO_IMPORT __attribute__((visibility("default")))
58 # define OIIO_EXPORT __attribute__((visibility("default")))
59 # define OIIO_LOCAL __attribute__((visibility("hidden")))
60 #endif
61 
62 #if defined(OpenImageIO_EXPORTS)
63 # define OIIO_API OIIO_EXPORT
64 #else
65 # define OIIO_API OIIO_IMPORT
66 #endif
67 
68 #if defined(OpenImageIO_Util_EXPORTS)
69 # define OIIO_UTIL_API OIIO_EXPORT
70 #else
71 # define OIIO_UTIL_API OIIO_IMPORT
72 #endif
73 
74 #if defined(OpenImageIO_C_EXPORTS)
75 # define OIIOC_API OIIO_EXPORT
76 #else
77 # define OIIOC_API OIIO_IMPORT
78 #endif