GoogleTest 1.6 with Cygwin 1.7: 'fileno' was not declared in this scope
GoogleTest 1.6与Cygwin 1.7:“fileno”没有在这个范围内声明。
Error message when building a simple test on Factorial() function in Eclipse CDT:
在Eclipse CDT中构建Factorial()函数的简单测试时出错消息:
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 running gcc 4.7.3 on Cygwin 1.7.22
Eclipse CDT 8.1在Cygwin 1.7.22上运行gcc 4.7.3。
gTest 1.6 succesfully built including demo tests, with cmake 2.8.9 on Cygwin 1.7.22
gTest 1.6成功完成包括demo测试,cmake 2.8.9在Cygwin 1.7.22上。
I've linked the built lib with full path, E:\lib\gtest-1.6.0\Cygwin\libgtest.a
我已经将构建的lib与full path联系在一起,E:\lib\gtest-1.6.0\Cygwin\ libgtesta。
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?
似乎错误与我的代码无关。有谁使用gTest与Eclipse和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));
}
2 个解决方案
#1
18
Setting the C++ standard to -std=gnu++0x rather than -std=c++0x, worked for me. You can try the statement:
将c++标准设置为-std=gnu++0x而不是-std=c++0x,为我工作。你可以试试这个声明:
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"
Setting symbol (-DGTEST_OS_CYGWIN=1) has got nothing to do with this error.
设置符号(-DGTEST_OS_CYGWIN=1)与此错误无关。
#2
7
Some functions go beyond the ANSI standard. These are disabled when you use std=c++11 (or std=c++0x).
有些功能超出了ANSI标准。当您使用std=c++11(或std=c++0x)时禁用这些功能。
Among them are fdopen
, fileno
and strdup
. There are two possibilities to use them:
其中包括fdopen, fileno和strdup。使用它们有两种可能:
- Use the GNU dialect (std=gnu++11).
- 使用GNU方言(std= GNU ++11)。
- If you want to compile without dialect and make a local exception, you can include stdio.h with the __STRICT_ANSI__ undefined. (see: Error "'fdopen' was not declared" found with g++ 4 that compiled with g++3)
- 如果您想要编译而不使用方言,并且创建一个本地异常,您可以包括stdio。h与__STRICT_ANSI__没有定义。(参见:“fdopen”未被声明为“g++ 4,用g++3编译”)
I have tested both on Suse Linux Enterprise 11, MinGW and Cygwin.
我已经在Suse Linux Enterprise 11, MinGW和Cygwin上测试过。
Addition: Another (possibly better) way to access non-ANSI symbols would be to add
添加:另一个(可能更好的)访问非ansi符号的方法是添加。
#define _POSIX_C_SOURCE 200809L
before the first #include in your file. This will give you access to most of the non-standard routines.
在第一个#包含在您的文件之前。这将使您能够访问大多数非标准例程。
Some functions (e.g. realpath(...)
) require
一些功能(例如realpath(…))需要。
#define _BSD_SOURCE
to be inserted on top of your file.
要插入到文件的顶部。
#1
18
Setting the C++ standard to -std=gnu++0x rather than -std=c++0x, worked for me. You can try the statement:
将c++标准设置为-std=gnu++0x而不是-std=c++0x,为我工作。你可以试试这个声明:
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"
Setting symbol (-DGTEST_OS_CYGWIN=1) has got nothing to do with this error.
设置符号(-DGTEST_OS_CYGWIN=1)与此错误无关。
#2
7
Some functions go beyond the ANSI standard. These are disabled when you use std=c++11 (or std=c++0x).
有些功能超出了ANSI标准。当您使用std=c++11(或std=c++0x)时禁用这些功能。
Among them are fdopen
, fileno
and strdup
. There are two possibilities to use them:
其中包括fdopen, fileno和strdup。使用它们有两种可能:
- Use the GNU dialect (std=gnu++11).
- 使用GNU方言(std= GNU ++11)。
- If you want to compile without dialect and make a local exception, you can include stdio.h with the __STRICT_ANSI__ undefined. (see: Error "'fdopen' was not declared" found with g++ 4 that compiled with g++3)
- 如果您想要编译而不使用方言,并且创建一个本地异常,您可以包括stdio。h与__STRICT_ANSI__没有定义。(参见:“fdopen”未被声明为“g++ 4,用g++3编译”)
I have tested both on Suse Linux Enterprise 11, MinGW and Cygwin.
我已经在Suse Linux Enterprise 11, MinGW和Cygwin上测试过。
Addition: Another (possibly better) way to access non-ANSI symbols would be to add
添加:另一个(可能更好的)访问非ansi符号的方法是添加。
#define _POSIX_C_SOURCE 200809L
before the first #include in your file. This will give you access to most of the non-standard routines.
在第一个#包含在您的文件之前。这将使您能够访问大多数非标准例程。
Some functions (e.g. realpath(...)
) require
一些功能(例如realpath(…))需要。
#define _BSD_SOURCE
to be inserted on top of your file.
要插入到文件的顶部。