编译程序时遇到错误:
| CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
| Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
| GTEST_MAIN_LIBRARY)
| Call Stack (most recent call first):
| C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
| C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.29/Modules/FindGTest.cmake:270 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
| third_party/testing.cmake:57 (find_package)
| CMakeLists.txt:387 (include)
检查 VS 中是安装了 Google Test 的:
或许这个只能用于 IDE, CMake 中无法使用吧.
重新安装:
1. 下载源代码
git clone git@github.com:google/googletest.git googletest
2. 使用 x64 Native Tools Command Prompt for VS 2022 进入源代码目录:
mkdir build
cd build
cmake ..
cmake --build . --config RelWithDebInfo
cmake -DBUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=D:/builds/googletest/setupfiles -P cmake_install.cmake
set CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH%;D:\builds\googletest\setupfiles
echo find_package(GTest REQUIRED) > test.txt
cmake -N -P test.txt