bsankaran / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Error with logging_unittest.cc building when gflags is installed #203

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Ubuntu 14.04 LTS, gcc 4.8.2

What steps will reproduce the problem?
1. install gflags-2.1.1 (with BUILD_SHARED_LIBS=ON)
2. download and configure (without additional options) glog-0.3.3
3. launch make...

Library builds well, but when it starts to make tests it catches following 
errors:

g++ -DHAVE_CONFIG_H -I. -I.. -I./src  -I../src  -pthread    -Wall 
-Wwrite-strings -Woverloaded-virtual -Wno-sign-compare  -DNO_FRAME_POINTER  -g 
-O2 -MT logging_unittest-logging_unittest.o -MD -MP -MF 
.deps/logging_unittest-logging_unittest.Tpo -c -o 
logging_unittest-logging_unittest.o `test -f 'src/logging_unittest.cc' || echo 
'../'`src/logging_unittest.cc
../src/logging_unittest.cc: In function ‘int main(int, char**)’:
../src/logging_unittest.cc:179:43: error: ‘ParseCommandLineFlags’ was not 
declared in this scope
   ParseCommandLineFlags(&argc, &argv, true);
                                           ^
../src/logging_unittest.cc:179:43: note: suggested alternative:
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:346:31: note:   
‘gflags::ParseCommandLineFlags’
 extern GFLAGS_DLL_DECL uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags);
                               ^
In file included from ../src/logging_unittest.cc:58:0:
../src/logging_unittest.cc: In static member function ‘static void 
Test_DeathNoAllocNewHook_logging::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:296:1: note: in expansion of macro ‘TEST’
 TEST(DeathNoAllocNewHook, logging) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:296:1: note: in expansion of macro ‘TEST’
 TEST(DeathNoAllocNewHook, logging) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:296:1: note: in expansion of macro ‘TEST’
 TEST(DeathNoAllocNewHook, logging) {
 ^
../src/logging_unittest.cc: In function ‘void TestRawLogging()’:
../src/logging_unittest.cc:308:3: error: ‘FlagSaver’ was not declared in 
this scope
   FlagSaver saver;
   ^
../src/logging_unittest.cc:308:3: note: suggested alternative:
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
../src/logging_unittest.cc:308:13: error: expected ‘;’ before ‘saver’
   FlagSaver saver;
             ^
../src/logging_unittest.cc: In function ‘void LogWithLevels(int, int, bool, 
bool)’:
../src/logging_unittest.cc:363:3: error: ‘FlagSaver’ was not declared in 
this scope
   FlagSaver saver;
   ^
../src/logging_unittest.cc:363:3: note: suggested alternative:
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
../src/logging_unittest.cc:363:13: error: expected ‘;’ before ‘saver’
   FlagSaver saver;
             ^
In file included from ../src/logging_unittest.cc:58:0:
../src/logging_unittest.cc: In static member function ‘static void 
Test_DeathRawCHECK_logging::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:436:1: note: in expansion of macro ‘TEST’
 TEST(DeathRawCHECK, logging) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:436:1: note: in expansion of macro ‘TEST’
 TEST(DeathRawCHECK, logging) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:436:1: note: in expansion of macro ‘TEST’
 TEST(DeathRawCHECK, logging) {
 ^
../src/logging_unittest.cc: In static member function ‘static void 
Test_DeathSTREQ_logging::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:586:1: note: in expansion of macro ‘TEST’
 TEST(DeathSTREQ, logging) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:586:1: note: in expansion of macro ‘TEST’
 TEST(DeathSTREQ, logging) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:586:1: note: in expansion of macro ‘TEST’
 TEST(DeathSTREQ, logging) {
 ^
../src/logging_unittest.cc: In static member function ‘static void 
Test_CheckNOTNULL_Simple::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:596:1: note: in expansion of macro ‘TEST’
 TEST(CheckNOTNULL, Simple) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:596:1: note: in expansion of macro ‘TEST’
 TEST(CheckNOTNULL, Simple) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:596:1: note: in expansion of macro ‘TEST’
 TEST(CheckNOTNULL, Simple) {
 ^
../src/logging_unittest.cc: In static member function ‘static void 
Test_DeathCheckNN_Simple::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:607:1: note: in expansion of macro ‘TEST’
 TEST(DeathCheckNN, Simple) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:607:1: note: in expansion of macro ‘TEST’
 TEST(DeathCheckNN, Simple) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:607:1: note: in expansion of macro ‘TEST’
 TEST(DeathCheckNN, Simple) {
 ^
../src/logging_unittest.cc: In static member function ‘static void 
Test_SafeFNMatch_logging::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:866:1: note: in expansion of macro ‘TEST’
 TEST(SafeFNMatch, logging) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:866:1: note: in expansion of macro ‘TEST’
 TEST(SafeFNMatch, logging) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:866:1: note: in expansion of macro ‘TEST’
 TEST(SafeFNMatch, logging) {
 ^
../src/logging_unittest.cc: In static member function ‘static void 
Test_Strerror_logging::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:1041:1: note: in expansion of macro ‘TEST’
 TEST(Strerror, logging) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:1041:1: note: in expansion of macro ‘TEST’
 TEST(Strerror, logging) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:1041:1: note: in expansion of macro ‘TEST’
 TEST(Strerror, logging) {
 ^
../src/logging_unittest.cc: In static member function ‘static void 
Test_UserDefinedClass_logging::Run()’:
../src/googletest.h:177:25: error: ‘FlagSaver’ was not declared in this 
scope
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:1206:1: note: in expansion of macro ‘TEST’
 TEST(UserDefinedClass, logging) {
 ^
../src/googletest.h:177:25: note: suggested alternative:
     static void Run() { FlagSaver fs; RunTest(); }      \
                         ^
../src/logging_unittest.cc:1206:1: note: in expansion of macro ‘TEST’
 TEST(UserDefinedClass, logging) {
 ^
In file included from ./src/glog/logging.h:85:0,
                 from ../src/utilities.h:82,
                 from ../src/logging_unittest.cc:33:
/usr/local/include/gflags/gflags.h:277:23: note:   ‘gflags::FlagSaver’
 class GFLAGS_DLL_DECL FlagSaver {
                       ^
In file included from ../src/logging_unittest.cc:58:0:
../src/googletest.h:177:35: error: expected ‘;’ before ‘fs’
     static void Run() { FlagSaver fs; RunTest(); }      \
                                   ^
../src/logging_unittest.cc:1206:1: note: in expansion of macro ‘TEST’
 TEST(UserDefinedClass, logging) {
 ^
make: *** [logging_unittest-logging_unittest.o] Error 1

I think that the problem is with namespace usage (gflags)

--
Senin Dmitry <seninds@gmail.com>

Original issue reported on code.google.com by senindmi...@gmail.com on 7 May 2014 at 10:11

GoogleCodeExporter commented 8 years ago
How to solve this problem?

Original comment by linyu...@gmail.com on 7 May 2014 at 12:04

GoogleCodeExporter commented 8 years ago
This is my patch for src directory:
diff -r glog-0.3.3/src/demangle_unittest.cc 
glog-0.3.3-new/src/demangle_unittest.cc
48a49,51
> #ifdef HAVE_LIB_GFLAGS
>   using namespace gflags;
> #endif
diff -r glog-0.3.3/src/logging_unittest.cc 
glog-0.3.3-new/src/logging_unittest.cc
81a82,84
> #ifdef HAVE_LIB_GFLAGS
>   using namespace gflags;
> #endif
diff -r glog-0.3.3/src/signalhandler_unittest.cc 
glog-0.3.3-new/src/signalhandler_unittest.cc
44a45,47
> #ifdef HAVE_LIB_GFLAGS
>   using namespace gflags;
> #endif
diff -r glog-0.3.3/src/symbolize_unittest.cc 
glog-0.3.3-new/src/symbolize_unittest.cc
45a46,48
> #ifdef HAVE_LIB_GFLAGS
>   using namespace gflags;
> #endif
diff -r glog-0.3.3/src/utilities_unittest.cc 
glog-0.3.3-new/src/utilities_unittest.cc
36a37,39
> #ifdef HAVE_LIB_GFLAGS
>   using namespace gflags;
> #endif

Original comment by senindmi...@gmail.com on 7 May 2014 at 3:03

GoogleCodeExporter commented 8 years ago
Add using instruction:

#ifdef HAVE_LIB_GFLAGS
  using namespace gflags;
#endif

in each unittest in the same place, where you declare other namespaces 
(GOOGLE_NAMESPACE and so on)

Original comment by senindmi...@gmail.com on 7 May 2014 at 3:07

GoogleCodeExporter commented 8 years ago
The patch is attached. Could you please apply it to the repository?

Original comment by carles.f...@gmail.com on 18 May 2014 at 2:12

Attachments:

GoogleCodeExporter commented 8 years ago
You forgot to correct src/signalhandler_unittest.cc.
I attach new patch file. This one works good on r142.

Original comment by senindmi...@gmail.com on 19 May 2014 at 6:13

Attachments:

GoogleCodeExporter commented 8 years ago
I got same error. Why this error happens especially in this environment?

Original comment by limh...@gmail.com on 9 Jun 2014 at 1:55

GoogleCodeExporter commented 8 years ago
Because using gflags functions and structures are declared in gflags namespace, 
but in unittests they are used without corresponding access specifier and 
"using namespace gflags" instruction. For example, line 179 in 
logging_unittest.cc:
ParseCommandLineFlags(&argc, &argv, true);

Original comment by senindmi...@gmail.com on 9 Jun 2014 at 10:27

GoogleCodeExporter commented 8 years ago
Excuse me, I still cannot compile even with the patch. 
One of the multiple errors is this : 
src/logging_unittest.cc:1041:1: error: ‘FlagSaver’ was not declared in this 
scope

Original comment by alessio....@gmail.com on 14 Oct 2014 at 4:52