Dynatrace OneAgent SDK for C/C++  1.7.1.1
onesdk_msvc.h
Go to the documentation of this file.
1 /*
2  Copyright 2017-2018 Dynatrace LLC
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef ONESDK_MSVC_H_INCLUDED
18 #define ONESDK_MSVC_H_INCLUDED
19 
20 /* IWYU pragma: private */
21 
26 #if defined(_MSC_VER)
27 
28 #include "onesdk/onesdk_common.h"
29 
30 #include <stdio.h>
31 
32 /*========================================================================================================================================*/
33 
34 #if defined(ONESDK_AUTO_LINK) && !defined(ONESDK_BUILD_LIBRARY)
35 
36 #if _MSC_VER >= 1900
37 /* The CRTs of Visual C++ 2015 and later provide the printf/scanf family as inline functions, but our static LIB requires them as normal
38  functions. => Link with legacy_stdio_definitions.lib where Visual C++ still provides them. */
39 #pragma comment(lib, "legacy_stdio_definitions.lib")
40 #endif
41 
42 #if defined(ONESDK_SHARED)
43 #pragma comment(lib, "onesdk_shared.lib")
44 #else
45 #pragma comment(lib, "onesdk_static.lib")
46 #endif
47 
48 #endif /* defined(ONESDK_AUTO_LINK) && !defined(ONESDK_BUILD_LIBRARY) */
49 
50 /*========================================================================================================================================*/
51 
52 /* The CRTs of Visual C++ 2015 and later use a different internal helper function for locating stdin/stdout/stderr than older Visual C++
53  versions. That makes static libraries incompatible between the two "generations".
54 
55  We can work around that by defining our own helper function in the consuming program which locates stderr for us.
56  Since we potentially do this in multiple translation units, we need __declspec(selectany), and since __declspec(selectany) only works
57  on variables and not on functions, we use a function pointer. */
58 
59 #if !defined(ONESDK_SHARED)
60 #if defined(ONESDK_BUILD_LIBRARY)
61 
62 /* Declare the pointer to our helper function for building our static library. */
63 
65 #if defined(__cplusplus)
66 extern "C"
67 #else
68 extern
69 #endif
70 FILE* (ONESDK_CALL* const onesdk_get_stderr)(void);
71 
72 #else
73 
74 /* Define the pointer to our helper function in the consuming application. */
75 
77 static FILE* ONESDK_CALL onesdk_get_stderr_impl(void) {
78  return stderr;
79 }
80 
82 #if defined(__cplusplus)
83 extern "C"
84 #else
85 extern
86 #endif
87 __declspec(selectany) FILE* (ONESDK_CALL* const onesdk_get_stderr)(void) = onesdk_get_stderr_impl;
88 
89 #endif
90 #endif
91 
92 /*========================================================================================================================================*/
93 
94 #endif /* defined(_MSC_VER) */
95 
96 #endif /* ONESDK_MSVC_H_INCLUDED */
Defines common types/constants/macros. Applications should not include this file directly.