GTest - isatty未在此范围内声明
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GTest - isatty未在此范围内声明相关的知识,希望对你有一定的参考价值。
我花了几个小时试图找出为什么我得到以下编译错误:
~/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在gtest / gtest.h和gtest / internal / gtest-port.h中。
有什么明显的东西我不见了吗?
答案
好像你不在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
以上是关于GTest - isatty未在此范围内声明的主要内容,如果未能解决你的问题,请参考以下文章