本文介绍了GoogleTest 1.6与Cygwin 1.7编译错误:'fileno'未在此范围中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GoogleTest 1.6 with Cygwin 1.7:'fileno'未在此范围内声明

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

在Eclipse CDT中对Factorial()函数构建简单测试时出现错误消息: / p>

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:\source\gtest-1.6.0\include" -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:\source\gtest-1.6.0\include/gtest/internal/gtest-internal.h:40:0,
                 from E:\source\gtest-1.6.0\include/gtest/gtest.h:57,
                 from ../src/challenge.cpp:11:
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h:1589:51: error: 'fileno' was not declared in this scope
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h:1595:57: error: 'strdup' was not declared in this scope
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h:1627:71: error: 'fdopen' was not declared in this scope

Eclipse CDT 8.1在Cygwin 1.7.22上运行gcc 4.7.3

Eclipse CDT 8.1 running gcc 4.7.3 on Cygwin 1.7.22

gTest 1.6成功构建,包括演示测试,在Cygwin 1.7.22上的cmake 2.8.9

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

我已经链接建立的lib与完整路径,E:\lib \gtest-1.6.0 \\ \\ cygwin \libgtest.a

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

手动添加了以下命令选项,没有它时出现同样的错误。

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

-DGTEST_OS_CYGWIN=1

看似错误与我的代码。任何人使用gTest与Eclipse和Cygwin?

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

谢谢你,

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));
}


推荐答案

将C ++标准设置为 - std = gnu ++ 0x而不是-std = c ++ 0x,为我工作。您可以尝试以下语句:

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:\source\gtest-1.6.0\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/challenge.d" -MT"src/challenge.d" -o "src/challenge.o" "../src/challenge.cpp"

设置符号(-DGTEST_OS_CYGWIN = 1)与此错误无关。

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

这篇关于GoogleTest 1.6与Cygwin 1.7编译错误:'fileno'未在此范围中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:41