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

Can not compile google test with MinGW on Windows

我尝试按照 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.

感谢您的回答。

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

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

如果您没有使用 MSYS shell,请尝试使用 "MinGW Makefiles" cmake 生成器。

cmake -G "MinGW Makefiles"

然后 运行 make.