E-rich
E-rich

Reputation: 9511

GTest - isatty not declared in this scope

I've spent hours trying to figure out why I'm getting the following compiling error:

 ~/src/example/build $ make
-- Downloading GMock / GTest version 1.8.0 from git
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/src/example/build
[  5%] Performing update step for 'gmock'
[ 10%] Performing configure step for 'gmock'
-- gmock configure command succeeded.  See also /home/user/src/example/build/gmock/src/gmock-stamp/gmock-configure-*.log
[ 15%] Performing build step for 'gmock'
-- gmock build command succeeded.  See also /home/user/src/example/build/gmock/src/gmock-stamp/gmock-build-*.log
[ 20%] No install step for 'gmock'
[ 25%] Completed 'gmock'
[ 40%] Built target gmock
[ 75%] Built target project-app
Scanning dependencies of target step_definition_runner
[ 80%] Building CXX object Target/project/CMakeFiles/step_definition_runner.dir/features/step_definitions/App_Steps.cpp.o
In file included from /home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-internal.h:40:0,
                 from /home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/gtest.h:58,
                 from /home/user/src/example/Target/project/features/step_definitions/App_Steps.cpp:1:
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h: In function ‘int testing::internal::posix::IsATTY(int)’:
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h:2341:45: error: ‘isatty’ was not declared in this scope
 inline int IsATTY(int fd) { return isatty(fd); }
                                             ^
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h: In function ‘int testing::internal::posix::RmDir(const char*)’:
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h:2347:53: error: ‘rmdir’ was not declared in this scope
 inline int RmDir(const char* dir) { return rmdir(dir); }
                                                     ^
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h: In function ‘int testing::internal::posix::ChDir(const char*)’:
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h:2365:53: error: ‘chdir’ was not declared in this scope
 inline int ChDir(const char* dir) { return chdir(dir); }
                                                     ^
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h: In function ‘int testing::internal::posix::Read(int, void*, unsigned int)’:
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h:2379:46: error: ‘read’ was not declared in this scope
   return static_cast<int>(read(fd, buf, count));
                                              ^
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h: In function ‘int testing::internal::posix::Write(int, const void*, unsigned int)’:
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h:2382:47: error: ‘write’ was not declared in this scope
   return static_cast<int>(write(fd, buf, count));
                                               ^
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h: In function ‘int testing::internal::posix::Close(int)’:
/home/user/src/example/build/gmock/src/gmock/googletest/include/gtest/internal/gtest-port.h:2384:43: error: ‘close’ was not declared in this scope
 inline int Close(int fd) { return close(fd); }
                                           ^
Target/project/CMakeFiles/step_definition_runner.dir/build.make:62: recipe for target 'Target/project/CMakeFiles/step_definition_runner.dir/features/step_definitions/App_Steps.cpp.o' failed
make[2]: *** [Target/project/CMakeFiles/step_definition_runner.dir/features/step_definitions/App_Steps.cpp.o] Error 1
CMakeFiles/Makefile2:164: recipe for target 'Target/project/CMakeFiles/step_definition_runner.dir/all' failed
make[1]: *** [Target/project/CMakeFiles/step_definition_runner.dir/all] Error 2
Makefile:94: recipe for target 'all' failed
make: *** [all] Error 2

I'm using the FindGMock.cmake from the cucumber-cpp project to handle the GTest dependency.

In my CMakeLists.txt file I have:

add_executable(step_definition_runner
    features/step_definitions/App_Steps.cpp
    )
target_include_directories(step_definition_runner
    PRIVATE
        ${GTEST_INCLUDE_DIRS}
    )
target_link_libraries(step_definition_runner project-app ${GTEST_LIBRARIES})

I've tried many things, but a couple of note:

Is there something obvious I'm missing?

Upvotes: 0

Views: 2438

Answers (2)

Tomaž Šuštar
Tomaž Šuštar

Reputation: 21

This was an issue im my case: I had another file named io.h is my include path, which got included instead of the Windows one. I renamed my own io.h to _io.h and I could build my gtest project again.

Upvotes: 2

Pavan Chandaka
Pavan Chandaka

Reputation: 12751

It seems like you are not on windows OS.

These functions are allowed only for windows

Look for below content in https://github.com/google/googletest/blob/master/googletest/include/gtest/internal/gtest-port.h

402 // Brings in definitions for functions used in the testing::internal::posix 
403 // namespace (read, write, close, chdir, isatty, stat). We do not currently 
404 // use them on Windows Mobile. 
405 #if GTEST_OS_WINDOWS 
406 # if !GTEST_OS_WINDOWS_MOBILE 
407 #  include <direct.h> 
408 #  include <io.h> 
409 # endif

Upvotes: 1

Related Questions