这是我的CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(/usr/include/gtest)
# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests gtest.cpp)
target_link_libraries(runTests /usr/lib/gtest pthread)
当运行cmake时,我遇到了以下错误:
michael@michaelFriko:~/workspace/gtest/src$ cmake CMakeLists.txt
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindGTest.cmake:150 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:8 (find_package)
如何解决这个问题?
GTEST_ROOT
应该是/usr
。该脚本使用include
和lib
作为包含目录和库目录的后缀,所以您应该没问题。 - ComicSansMS/usr/lib
目录下的gtest
子目录中?因为这样不行。你需要将libgtest.*
文件直接放在/usr/lib/
中,而非其子目录中。 - ComicSansMS