Fixed typedef redefinition errors when including both SDL_vulkan.h and vulkan.h You should always include vulkan/vulkan.h first, then include SDL_vulkan.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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
diff --git a/include/SDL.h b/include/SDL.h
index 4cd6108..366d50f 100644
--- a/include/SDL.h
+++ b/include/SDL.h
@@ -40,10 +40,10 @@
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_filesystem.h"
-#include "SDL_joystick.h"
#include "SDL_gamecontroller.h"
#include "SDL_haptic.h"
#include "SDL_hints.h"
+#include "SDL_joystick.h"
#include "SDL_loadso.h"
#include "SDL_log.h"
#include "SDL_messagebox.h"
@@ -51,12 +51,12 @@
#include "SDL_power.h"
#include "SDL_render.h"
#include "SDL_rwops.h"
+#include "SDL_shape.h"
#include "SDL_system.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "SDL_version.h"
#include "SDL_video.h"
-#include "SDL_vulkan.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
diff --git a/include/SDL_vulkan.h b/include/SDL_vulkan.h
index d56c3d8..6c7d305 100644
--- a/include/SDL_vulkan.h
+++ b/include/SDL_vulkan.h
@@ -1,23 +1,23 @@
/*
- Simple DirectMedia Layer
- Copyright (C) 2017, Mark Callow.
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
- */
+ Simple DirectMedia Layer
+ Copyright (C) 2017, Mark Callow
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
/**
* \file SDL_vulkan.h
@@ -36,8 +36,11 @@
extern "C" {
#endif
-/* Avoid including vulkan.h */
-#ifndef VULKAN_H_
+/* Avoid including vulkan.h, don't define VkInstance if it's already included */
+#ifdef VULKAN_H_
+#define NO_SDL_VULKAN_TYPEDEFS
+#endif
+#ifndef NO_SDL_VULKAN_TYPEDEFS
#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
@@ -49,7 +52,7 @@ extern "C" {
VK_DEFINE_HANDLE(VkInstance)
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
-#endif /* !VULKAN_H_ */
+#endif /* !NO_SDL_VULKAN_TYPEDEFS */
typedef VkInstance SDL_vulkanInstance;
typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c
index f49534b..1d09220 100644
--- a/src/dynapi/SDL_dynapi.c
+++ b/src/dynapi/SDL_dynapi.c
@@ -32,9 +32,9 @@
#include "SDL.h"
-/* !!! FIXME: Shouldn't these be included in SDL.h? */
-#include "SDL_shape.h"
+/* These headers have system specific definitions, so aren't included above */
#include "SDL_syswm.h"
+#include "SDL_vulkan.h"
/* This is the version of the dynamic API. This doesn't match the SDL version
and should not change until there's been a major revamp in API/ABI.
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 5b2bea5..d2709be 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -26,7 +26,8 @@
#include "SDL_messagebox.h"
#include "SDL_shape.h"
#include "SDL_thread.h"
-#include "SDL_vulkan.h"
+
+#include "SDL_vulkan_internal.h"
/* The SDL video driver */
diff --git a/src/video/SDL_vulkan_internal.h b/src/video/SDL_vulkan_internal.h
index 9bcfcda..b42da01 100644
--- a/src/video/SDL_vulkan_internal.h
+++ b/src/video/SDL_vulkan_internal.h
@@ -18,8 +18,8 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
-#ifndef _SDL_vulkan_internal_h
-#define _SDL_vulkan_internal_h
+#ifndef SDL_vulkan_internal_h_
+#define SDL_vulkan_internal_h_
#include "../SDL_internal.h"
@@ -53,14 +53,13 @@
#define VK_USE_PLATFORM_XCB_KHR
#endif
-#if SDL_VIDEO_VULKAN_SURFACE
-
-/* Need vulkan.h for the following declarations. Must ensure the first
- * inclusion of vulkan has the appropriate USE_PLATFORM defined, hence
- * the above. */
#define VK_NO_PROTOTYPES
#include "./khronos/vulkan/vulkan.h"
+#include "SDL_vulkan.h"
+
+#if SDL_VIDEO_VULKAN_SURFACE
+
extern const char *SDL_Vulkan_GetResultString(VkResult result);
extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
@@ -73,8 +72,8 @@ extern SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
const char **userNames,
unsigned nameCount,
const char *const *names);
+#endif /* SDL_VIDEO_VULKAN_SURFACE */
-#endif
+#endif /* SDL_vulkan_internal_h_ */
-#endif
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/test/testvulkan.c b/test/testvulkan.c
index 0c9f708..95cbec8 100644
--- a/test/testvulkan.c
+++ b/test/testvulkan.c
@@ -33,6 +33,7 @@ int main(int argc, char *argv[])
/* SDL includes a copy for building on systems without the Vulkan SDK */
#include "../src/video/khronos/vulkan/vulkan.h"
#endif
+#include "SDL_vulkan.h"
#ifndef UINT64_MAX /* VS2008 */
#define UINT64_MAX 18446744073709551615