GTest - isatty 未在此范围内声明

问题描述 投票:0回答:2

我花了几个小时试图弄清楚为什么会出现以下编译错误:

 ~/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

我正在使用 cucumber-cpp 项目中的 FindGMock.cmake 来处理 GTest 依赖项。

在我的 CMakeLists.txt 文件中,我有:

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

我尝试了很多东西,但有几点要注意:

  • 在包含gtest/gtest.h.之前包含unistd.h
  • 强制包括 unistd.h inside gtest/gtest.hgtest/internal/gtest-port.h.

有什么明显的我想念的东西吗?

c++ cmake googletest googlemock
2个回答
1
投票

看来你不是在windows操作系统上。

这些功能只允许用于windows

在以下内容中查找 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

0
投票

这是我的问题:我有另一个名为

io.h
的文件是我的包含路径,它被包含而不是 Windows 文件。我将自己的
io.h
重命名为
_io.h
,我可以再次构建我的gtest项目。

© www.soinside.com 2019 - 2024. All rights reserved.