[Cogl] [1.18][Patch]: Update cogl-sdl.h to avoid linking to the SDL libraries for Cogl-based applications

Fan Chun-wei fanc999 at yahoo.com.tw
Thu Feb 27 03:27:11 PST 2014


Hi,

Currently, on MSVC builds, applications built against Cogl builds with 
SDL support enabled will incur a dependency on the SDL/SDL2 DLL, which 
is not optimal as those applications may well be not really needing SDL 
directly.  This updates the cogl-sdl.h header so that it will undef main 
on Windows after the SDL headers are included, so that SDL's special 
main() will not be needed, eliminating the need to link to the SDLmain 
(and therefore the SDL DLL).  Applications needing SDL functionality and 
Cogl can then link to SDL as needed.

With blessings, thanks for the reviews!
-------------- next part --------------
From 6bbc2d4e54a53d16f4cbc0487c0cb248f9f9642f Mon Sep 17 00:00:00 2001
From: Chun-wei Fan <fanchunwei at src.gnome.org>
Date: Thu, 27 Feb 2014 18:55:11 +0800
Subject: [PATCH 2/5] cogl/cogl.h: Avoid Linking to SDLmain on Windows

This undef's the main function after including the SDL/SDL2 headers so that
it will not be necessary to link to the SDLmain (and hence SDL) libraries.

The advantage to this approach is that applications based on Cogl (and
therefore Clutter) will not have a implicit dependency on the SDL/SDL2
DLL, unless Cogl itself is built and linked against SDL.
---
 cogl/cogl-sdl.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/cogl/cogl-sdl.h b/cogl/cogl-sdl.h
index 220e004..8da4ba3 100644
--- a/cogl/cogl-sdl.h
+++ b/cogl/cogl-sdl.h
@@ -52,13 +52,13 @@
 #include <cogl/cogl-onscreen.h>
 #include <SDL.h>
 
-#ifdef _MSC_VER
-/* We need to link to SDL.lib/SDLmain.lib
- * if we are using Cogl
- * that uses the SDL winsys
+#ifdef COGL_HAS_WIN32_SUPPORT
+/* Avoid the necessity of linking to the SDL libraries, as
+ * it adds an implicit run-time depenency for Cogl-based
+ * apps on the SDL DLLs
  */
-#pragma comment (lib, "SDL.lib")
-#pragma comment (lib, "SDLmain.lib")
+
+#undef main
 #endif
 
 COGL_BEGIN_DECLS
-- 
1.8.3.msysgit.0


More information about the Cogl mailing list