Fix VS linker warning regarding locally defined FLAGS_tryfromenv symbol.
authorAndreas Schuh <andreas.schuh.84@gmail.com>
Mon, 17 Mar 2014 21:20:24 +0000 (21:20 +0000)
committerAndreas Schuh <andreas.schuh.84@gmail.com>
Mon, 17 Mar 2014 21:20:24 +0000 (21:20 +0000)
src/gflags.cc
src/gflags_declare.h.in
test/gflags_unittest.cc

index 0f1f0b0..2e0b89c 100644 (file)
 #include "mutex.h"
 #include "util.h"
 
+// Export the following flags only if the gflags library is a DLL
+#ifndef GFLAGS_SHARED_LIBS
+#  undef  GFLAGS_DLL_DEFINE_FLAG
+#  define GFLAGS_DLL_DEFINE_FLAG
+#endif
 
 // Special flags, type 1: the 'recursive' flags.  They set another flag's val.
 DEFINE_string(flagfile,   "", "load flags from file");
@@ -395,8 +400,7 @@ const char* FlagValue::TypeName() const {
     assert(false);
     return "";
   }
-  // Directly indexing the strigns in the 'types' string, each of them
-  // is 7 bytes long.
+  // Directly indexing the strings in the 'types' string, each of them is 7 bytes long.
   return &types[type_ * 7];
 }
 
index 99a7c2d..a9b7b6a 100644 (file)
 #  endif
 #endif
 
-// We always want to export defined variables, dll or no
-#if defined(_MSC_VER)
-#  define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
-#else
-#  define GFLAGS_DLL_DEFINE_FLAG
+// By default, we always want to export defined variables, assuming
+// that the DEFINE_FLAG macros are used within shared modules.
+#ifndef GFLAGS_DLL_DEFINE_FLAG
+#  if defined(_MSC_VER)
+#    define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
+#  else
+#    define GFLAGS_DLL_DEFINE_FLAG
+#  endif
 #endif
 
-// We always want to import declared variables, dll or no
-#if defined(_MSC_VER)
-#  define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
-#else
-#  define GFLAGS_DLL_DECLARE_FLAG
+// By default, we always want to export defined variables, assuming
+// that the DECLARE_FLAG macros are used within shared modules.
+#ifndef GFLAGS_DLL_DECLARE_FLAG
+#  if defined(_MSC_VER)
+#    define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport)
+#  else
+#    define GFLAGS_DLL_DECLARE_FLAG
+#  endif
 #endif
 
 // Export/import of STL class instantiations
index 185d562..8f3096b 100644 (file)
 #include "config_for_unittests.h"
 #include <gflags/gflags.h>
 
+#ifndef GFLAGS_SHARED_LIBS
+#  undef  GFLAGS_DLL_DECLARE_FLAG
+#  define GFLAGS_DLL_DECLARE_FLAG
+#endif
+
 #include <math.h>       // for isinf() and isnan()
 #include <stdio.h>
 #include <stdlib.h>