-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshareLib.h
158 lines (149 loc) · 5.28 KB
/
shareLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Use compiler specific key words to set up shareable library
* external symbols and entry points
*
* Right now this is only necessary for WIN32 DLL, and to a lesser extent VAXC.
* The approach should be general enough for future systems, however.
*
*
* USAGE:
*
* In header files, declare variables, classes and functions
* to be __exported__ like this:
*
* epicsShareFunc int epicsShareAPI
* a_func (int arg); function prototype
* or
* epicsShareFunc int epicsShareAPIV
* a_func (int arg, ...); variable args function prototype
* (using either ... or va_list)
* epicsShareExtern int a_var; reference variable
* (reference declaration)
* epicsShareDef int a_var= 4; create variable instance
* (definition declaration)
* class epicsShareClass a_class; reference a class
*
* Usually the epicsShare... macros expand to
* "import this from a DLL" (on WIN32, on Unix it's a NOOP)
*
* In the implementation file, however, you write:
*
* #include <routines_imported.h>
* #include <routines_imported_from_other_dlls.h>
* #define epicsExportSharedSymbols
* ! no more includes specifying routines outside this DLLs from here on !
* #include <shareLib.h>
* #include <in_this_dll_but_not_implemented_in_this_file.h>
* #include <what_I_implement_in_this_file.h>
*
* The point is: define epicsExportSharedSymbols exactly and only
* right before you include the prototypes for what you implement!
* Then include shareLib.h again because this is where they get changed.
* This time the epicsShare... macros expand to
* "export this from the DLL that we are building". (again only on WIN32)
*
* NOTE:
* If what_I_implement_in_this_file.h includes header files for routines that
* are not implemented in the DLL, then you will need to force these
* header files to be included before setting epicsExportSharedSymbols,
* including shareLib.h, and including what_I_implement_in_this_file.h. Since
* all well written header files have "ifdef" guards against multiple inclusion
* this is only a matter of "preincluding" the headers for these DLL
* imports before epicsExportSharedSymbols is defined. This
* is admittedly a bit of a mess, but is fortunately only the concern of
* persons who are adding routines to a library, and will have no impact
* on persons using routines out of a library.
*
* 8-22-96 -kuk-
*/
#undef epicsShareExtern
#undef epicsShareDef
#undef epicsShareClass
#undef epicsShareFunc
#undef epicsShareAPI
#undef epicsShareAPIV
#undef READONLY
/*
* if its WIN32 and it isnt the Cygnus GNU environment
* (I am assuming Borlund and other MS Vis C++ competitors
* support these MS VisC++ defacto standard keywords???? If not
* then we should just switch on defined(_MSC_VER) here)
*
* Also check for "EPICS_DLL_NO" not defined so that we will not use these
* keywords if it is an object library build of base under WIN32.
*/
#if defined(_WIN32) && !defined(__CYGWIN32__)
# if defined(epicsExportSharedSymbols)
# if defined(EPICS_DLL_NO) /* this indicates that we are not building a DLL */
# define epicsShareExtern extern
# define epicsShareClass
# define epicsShareFunc
# else
# define epicsShareExtern extern __declspec(dllexport)
# define epicsShareClass __declspec(dllexport)
# define epicsShareFunc __declspec(dllexport)
# endif
# else
# if defined(_DLL) /* this indicates that we are being compiled to call a DLL */
# define epicsShareExtern extern __declspec(dllimport)
# define epicsShareClass __declspec(dllimport)
# define epicsShareFunc __declspec(dllimport)
# else
# define epicsShareExtern extern
# define epicsShareClass
# define epicsShareFunc
# endif
# endif
/*
* Subroutine removes arguments
* (Bill does not allow __stdcall to be next to
* __declspec(xxxx))
*/
# define epicsShareAPI __stdcall
/*
* Variable args functions cannot be __stdcall
* Use this for variable args functions
* (Those using either ... or va_list arguments)
*/
# define epicsShareAPIV __cdecl
# if defined(EPICS_DLL_NO) /* this indicates that we are not building a DLL */
# define epicsShareDef
# else
# define epicsShareDef __declspec(dllexport)
# endif
# define READONLY const
/*
* if its the old VAX C Compiler (not DEC C)
*/
#elif defined(VAXC)
/*
* VAXC creates FORTRAN common blocks when
* we use "extern int fred"/"int fred=4". Therefore,
* the initialization is not loaded unless we
* call a function in that object module.
*
* DEC CXX does not have this problem.
* We suspect (but do not know) that DEC C
* also does not have this problem.
*/
# define epicsShareExtern globalref
# define epicsShareDef globaldef
# define READONLY const
# define epicsShareClass
# define epicsShareFunc
# define epicsShareAPI
# define epicsShareAPIV
#else
/* else => no import/export specifiers */
# define epicsShareExtern extern
# define epicsShareAPI
# define epicsShareAPIV
# define epicsShareClass
# define epicsShareDef
# define epicsShareFunc
# if defined(__STDC__)
# define READONLY const
# else
# define READONLY
# endif
#endif