无法在Windows上使用MinGW编译谷歌测试

时间:2016-09-17 17:12:17

标签: c++ windows mingw googletest

我尝试按照this post的说明在Windows上使用MinGW编译google测试框架,但在执行make时出错:

[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from d:/downloads/googletest-master/googletest/src/gtest-all.cc:45:0:
D:/downloads/googletest-master/googletest/src/gtest-port.cc: In static member function 'static void testing::internal::ThreadLocalRegistryImpl::StartWatcherThreadFor(DWORD)':
D:/downloads/googletest-master/googletest/src/gtest-port.cc:495:21: error: '::OpenThread' has not been declared
     HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
                     ^
make[2]: *** [CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
make[1]: *** [CMakeFiles/gtest.dir/all] Error 2
make: *** [all] Error 2

请帮忙。我试过了:

cmake -G "MSYS Makefiles" --with-pthreads=no

但得到了:

CMake Error: The source directory "D:/downloads/googletest-master/googletest/--with-pthreads=no" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

感谢您的回答。

1 个答案:

答案 0 :(得分:0)

cmake -G "MSYS Makefiles" --with-pthreads=no

我认为--with-pthreads=no不是有效的cmake选项。 CMake尝试将其解释为源目录。删除该选项。我认为谷歌测试无论如何都需要pthreads,这就是为什么OpenThread未被声明,因为它取决于pthreads

如果您没有使用MSYS shell,请尝试使用“MinGW Makefile”生成器进行cmake。

cmake -G "MinGW Makefiles"

然后运行make