Revision: 73017
          http://sourceforge.net/p/brlcad/code/73017
Author:   starseeker
Date:     2019-05-07 15:38:33 +0000 (Tue, 07 May 2019)
Log Message:
-----------
Don't know if this works, and it definitely doesn't attempt a glib style 
solution to the VS2015 issue, but it should at least compile.

Modified Paths:
--------------
    brlcad/trunk/include/common.h
    brlcad/trunk/src/libbu/init.c

Modified: brlcad/trunk/include/common.h
===================================================================
--- brlcad/trunk/include/common.h       2019-05-07 14:09:11 UTC (rev 73016)
+++ brlcad/trunk/include/common.h       2019-05-07 15:38:33 UTC (rev 73017)
@@ -384,15 +384,17 @@
 #  undef INITIALIZE
 #  warning "INITIALIZE unexpectedly defined.  Ensure common.h is included 
first."
 #endif
+
 #ifdef __cplusplus
+
 #  define INITIALIZE(lib) \
         static void lib(void); \
         struct lib##_t_ { lib##_t_(void) { lib(); } }; static lib##_t_ lib##_; 
\
         static void lib(void)
+
 #elif defined(_MSC_VER)
 
-/* TODO - below code is not building on Visual Studio 2015.  We may also have
- * some issues with this in 2015 optimized builds.  See:
+/* We may have issues with this trick in 2015 optimized builds.  See:
  *
  * https://bugzilla.gnome.org/show_bug.cgi?id=752837
  * https://github.com/GNOME/glib/blob/master/glib/gconstructor.h
@@ -400,21 +402,28 @@
  * for what the glib folks had to go through, and even after all that they had
  * to leave their static build broken on Windows... */
 
-#  pragma section(".CRT$XCU",read)
-#  define INITIALIZE_MSVC(lib, p) \
+#  ifdef _WIN64
+#    define INITIALIZE(lib) \
+        __pragma(section(".CRT$XCU",read)) \
         static void lib(void); \
         __declspec(allocate(".CRT$XCU")) void (*lib##_)(void) = lib; \
-        __pragma(comment(linker,"/include:" p #lib "_")) \
+        __pragma(comment(linker,"/include:" #lib "_")) \
         static void lib(void)
-#  ifdef _WIN64
-#    define INITIALIZE(lib) INITIALIZE_MSVC(lib,"")
 #  else
-#    define INITIALIZE(lib) INITIALIZE_MSVC(lib,"_")
+#    define INITIALIZE(lib) \
+        __pragma(section(".CRT$XCU",read)) \
+        static void lib(void); \
+        __declspec(allocate(".CRT$XCU")) void (*lib##_)(void) = lib; \
+        __pragma(comment(linker,"/include:" "_" #lib "_")) \
+        static void lib(void)
 #  endif
+
 #else
+
 #  define INITIALIZE(lib) \
         static void lib(void) __attribute__((constructor)); \
         static void lib(void)
+
 #endif
 
 

Modified: brlcad/trunk/src/libbu/init.c
===================================================================
--- brlcad/trunk/src/libbu/init.c       2019-05-07 14:09:11 UTC (rev 73016)
+++ brlcad/trunk/src/libbu/init.c       2019-05-07 15:38:33 UTC (rev 73017)
@@ -48,6 +48,16 @@
 int BU_SEM_DATETIME;
 int BU_SEM_DIR;
 
+/* The Visual C compiler pragmas needed for INITIALIZE specify a "read"
+ * attribute, which is conflicting with the system definition of read:
+ *
+ * #define read _read
+ *
+ * For the INITIALIZE macro to work with Visual C, we have to first #undef
+ * read anywhere we call it so the subsequent macro expansion will work. */
+#if defined(_WIN32)
+#  undef read
+#endif
 
 INITIALIZE(libbu)
 {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to