Fix the gflags namespace issue
authorKai Li <kaili_kloud@163.com>
Sat, 9 Aug 2014 12:11:38 +0000 (20:11 +0800)
committerKai Li <kaili_kloud@163.com>
Sat, 9 Aug 2014 12:29:53 +0000 (20:29 +0800)
include/caffe/common.hpp
src/caffe/common.cpp
tools/caffe.cpp

index 97a3496..9008eae 100644 (file)
@@ -2,6 +2,7 @@
 #define CAFFE_COMMON_HPP_
 
 #include <boost/shared_ptr.hpp>
+#include <gflags/gflags.h>
 #include <glog/logging.h>
 
 #include <cmath>
 
 #include "caffe/util/device_alternate.hpp"
 
+// gflags 2.1 issue: namespace google was changed to gflags without warning.
+// Luckily we will be able to use GFLAGS_GFAGS_H_ to detect if it is version
+// 2.1. If yes , we will add a temporary solution to redirect the namespace.
+// TODO(Yangqing): Once gflags solves the problem in a more elegant way, let's
+// remove the following hack.
+#ifndef GFLAGS_GFLAGS_H_
+namespace gflags = google;
+#endif  // GFLAGS_GFLAGS_H_
+
 // Disable the copy and assignment operator for a class.
 #define DISABLE_COPY_AND_ASSIGN(classname) \
 private:\
index 99b2292..e6c0a4f 100644 (file)
@@ -1,4 +1,3 @@
-#include <gflags/gflags.h>
 #include <glog/logging.h>
 #include <cstdio>
 #include <ctime>
@@ -6,17 +5,6 @@
 #include "caffe/common.hpp"
 #include "caffe/util/rng.hpp"
 
-// gflags 2.1 issue: namespace google was changed to gflags without warning.
-// Luckily we will be able to use GFLAGS_GFAGS_H_ to detect if it is version
-// 2.1. If yes , we will add a temporary solution to redirect the namespace.
-// TODO(Yangqing): Once gflags solves the problem in a more elegant way, let's
-// remove the following hack.
-#ifdef GFLAGS_GFLAGS_H_
-namespace google {
-using ::gflags::ParseCommandLineFlags;
-}  // namespace google
-#endif  // GFLAGS_GFLAGS_H_
-
 namespace caffe {
 
 shared_ptr<Caffe> Caffe::singleton_;
@@ -44,7 +32,7 @@ int64_t cluster_seedgen(void) {
 
 void GlobalInit(int* pargc, char*** pargv) {
   // Google flags.
-  ::google::ParseCommandLineFlags(pargc, pargv, true);
+  ::gflags::ParseCommandLineFlags(pargc, pargv, true);
   // Google logging.
   ::google::InitGoogleLogging(*(pargv)[0]);
 }
index 22d9eb1..13398ae 100644 (file)
@@ -1,4 +1,3 @@
-#include <gflags/gflags.h>
 #include <glog/logging.h>
 
 #include <cstring>