Googletest: gtest-port.h fileno not declared in scope

Created on 27 Jun 2016  Â·  14Comments  Â·  Source: google/googletest

I'm getting errors in gtest-port.h. Have tried various flags none are working.

Have searched and found similar errors, but no definitive solutions.

Any help is appreciated.

Thanks!

CYGWIN_NT-6.1 BaguaDragon 2.5.2(0.297/5/3) 2016-06-23 14:29 x86_64 Cygwin
g++ (GCC) 5.4.0

g++ -static -std=c++0x -DGTEST_OS_CYGWIN=1 -pthread -MMD -c main.cpp -o build/main.o -I /home/ssi112/cpp/googletest-master/googletest -I /home/ssi112/cpp/googletest-master/googletest/include -I . -I ../src -I ../../class-library/include
In file included from /home/ssi112/cpp/googletest-master/googletest/include/gtest/internal/gtest-internal.h:40:0,
from /home/ssi112/cpp/googletest-master/googletest/include/gtest/gtest.h:58,
from main.cpp:9:
/home/ssi112/cpp/googletest-master/googletest/include/gtest/internal/gtest-port.h: In function ‘int testing::internal::posix::FileNo(FILE_)’:
/home/ssi112/cpp/googletest-master/googletest/include/gtest/internal/gtest-port.h:2340:51: error: ‘fileno’ was not declared in this scope
inline int FileNo(FILE_ file) { return fileno(file); }
^
/home/ssi112/cpp/googletest-master/googletest/include/gtest/internal/gtest-port.h: In function ‘char* testing::internal::posix::StrDup(const char_)’:
/home/ssi112/cpp/googletest-master/googletest/include/gtest/internal/gtest-port.h:2346:57: error: ‘strdup’ was not declared in this scope
inline char_ StrDup(const char* src) { return strdup(src); }
^
/home/ssi112/cpp/googletest-master/googletest/include/gtest/internal/gtest-port.h: In function ‘FILE* testing::internal::posix::FDOpen(int, const char_)’:
/home/ssi112/cpp/googletest-master/googletest/include/gtest/internal/gtest-port.h:2374:71: error: ‘fdopen’ was not declared in this scope
inline FILE_ FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
^
In file included from main.cpp:12:0:
aggregate_test.hpp: In member function ‘virtual void AggregateTest_verifySplitAndFindAggregateFunctionality_Test::TestBody()’:
aggregate_test.hpp:11:32: error: conversion from ‘void’ to non-scalar type ‘std::string {aka std::basic_string}’ requested
std::string actual = aggregate(1, line);
^
make: *** [Makefile:28: build/main.o] Error 1

help wanted

All 14 comments

Same error for me using Cygwin on Windows 10.
Everything works fine when working on Ubuntu with the same source files...
Everything is updated to the current last version: Cygwin, Windows 10 and Ubuntu.

I can confirm. I have the exact same issue with Cygwin on Windows 10

EDIT: I solved it, I simply changes the "-std=c++0x" option into "-std=gnu++0x"
Credit goes to http://stackoverflow.com/questions/29692136/error-fileno-was-not-declared-in-this-scope

I have a similar situation. Compilation fails like this with -std=c++11 but then passes with -std=gnu++11

This issue isn't exactly solved. Any project that has stricter requirements, i.e. for c++xx instead of gnu++xx, gtest still doesn't work.

I should add, it also blatantly goes against the README requirement of a c++11 compliant compiler. Clearly that's not enough :)

Anything related to CMake is community supported. We do not use it internally and we are not in position to check. In general the maintainers would look for community consensus. Someone needs to review such PRs and comment on them.
With that, should I re-open this issue? Please let me know
Thanks

Yes please! It's got nothing to do with CMake from where I'm standing.

@jfinkhaeuser I am re-opening this issue. It is not clear from the description and the conversation exactly what the problem is and on what platform. If this is CygWin specific - the maintainers are not in position to help. We do not use CygWin and we do not have any tests running against it. it would have to be a community effort to troubleshoot and support CygWin.

The best possible outcome would be
1) Find the solution
2) Adding CI configuration ( I guess on appveyor.xml since cygwin runs under windows ) to make sure that the problem stays fixed going forward

The problem is that on Cygwin at least, the gtest-ports.h header is looking for e.g. the fileno function, which under the C++11 standard does not exist. The extended GNU++11 standard does support it.

So the README's claim that a C++11 compliant compiler is required isn't true on Cygwin; Cygwin requires more from the compiler.

I ran into the issue on Cygwin, but really that's a more general problem of what C++ standard you actually support - it just happens to break on Cygwin.

Revisiting this bug: we don't support Cygwin, and aren't in a position to test and fix this.

If the community can provide a patch which fixes this in Cygwin and does not impact supported platforms, we would be happy to accept it.

Let me see if I can find time for this today.

Reproduce:

$ cd /path/to/build
$ CXXFLAGS=-std=c++11 cmake /path/to/source
$ make

Will open a PR later.

Workaround:

$ cd /path/to/build
$ CXXFLAGS=-std=gnu++11 cmake /path/to/source
$ make

TL;DR is, some functions aren't standard, but part of GNU.

Was this page helpful?
0 / 5 - 0 ratings