Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

c++ - GoogleTest 1.6 with Cygwin 1.7 compile error: 'fileno' was not declared in this scope

GoogleTest 1.6 with Cygwin 1.7: 'fileno' was not declared in this scope

Error message when building a simple test on Factorial() function in Eclipse CDT:

Invoking: Cygwin C++ Compiler
g++ -std=c++0x -DGTEST_OS_CYGWIN=1 -I"E:sourcegtest-1.6.0include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/challenge.d" -MT"src/challenge.d" -o "src/challenge.o" "../src/challenge.cpp"
In file included from E:sourcegtest-1.6.0include/gtest/internal/gtest-internal.h:40:0,
                 from E:sourcegtest-1.6.0include/gtest/gtest.h:57,
                 from ../src/challenge.cpp:11:
E:sourcegtest-1.6.0include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
E:sourcegtest-1.6.0include/gtest/internal/gtest-port.h:1589:51: error: 'fileno' was not declared in this scope
E:sourcegtest-1.6.0include/gtest/internal/gtest-port.h:1595:57: error: 'strdup' was not declared in this scope
E:sourcegtest-1.6.0include/gtest/internal/gtest-port.h:1627:71: error: 'fdopen' was not declared in this scope

Eclipse CDT 8.1 running gcc 4.7.3 on Cygwin 1.7.22

gTest 1.6 succesfully built including demo tests, with cmake 2.8.9 on Cygwin 1.7.22

I've linked the built lib with full path, E:libgtest-1.6.0Cygwinlibgtest.a

The following command option was added manually, got same error without it.

-DGTEST_OS_CYGWIN=1

Seems the errors have nothing to do with my code. Anyone using gTest with Eclipse and Cygwin?

Thank you,

unsigned long Factorial(unsigned n) {
    return n==0? 0 : n*Factorial(n-1);
}

// Tests factorial of 0.
TEST(FactorialTest, HandlesZeroInput) {
  EXPECT_EQ(1, Factorial(0));
}

// Tests factorial of positive numbers.
TEST(FactorialTest, HandlesPositiveInput) {
  EXPECT_EQ(1, Factorial(1));
  EXPECT_EQ(2, Factorial(2));
  EXPECT_EQ(6, Factorial(3));
  EXPECT_EQ(40320, Factorial(8));
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Setting the C++ standard to -std=gnu++0x rather than -std=c++0x, worked for me. You can try the statement:

g++ -std=gnu++0x -DGTEST_OS_CYGWIN=1 -I"E:sourcegtest-1.6.0include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/challenge.d" -MT"src/challenge.d" -o "src/challenge.o" "../src/challenge.cpp"

Setting symbol (-DGTEST_OS_CYGWIN=1) has got nothing to do with this error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...