0

Colleagues !

I try to write simple application with google test and cmake. I do as written in documentation. My CMakeLists.txt is

cmake_minimum_required (VERSION 2.6)
project (foo_d-google-test)
add_executable (foo_d-google-test main.cpp)
enable_testing()
find_package(GTest REQUIRED)
if (NOT GTest_FOUND) 
    message(FATAL_ERROR "Cannot find Google Test Framework!")
endif()

and main.cpp is

#include <math.h>
#include <gtest/gtest.h>

TEST (SquareRootTest, PositiveNos) {
    EXPECT_EQ (18.0, sqrt (324.0));
    EXPECT_EQ (25.4, sqrt (645.16));
    EXPECT_EQ (50.3321, sqrt (2533.310224));
}

TEST (SquareRootTest, ZeroAndNegativeNos) {
    ASSERT_EQ (0.0, sqrt (0.0));
    ASSERT_EQ (-1, sqrt (-22.0));
 }

 int main(int argc, char* argv[])
 {
    testing::InitGoogleTest(&argc, argv);
    int ret = RUN_ALL_TESTS();
    return ret;
 }

And I receive an error

CMake Error at /usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message): Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)

My platform is Debian Linux 9, and library googletest was installed. Any idea ?

Thanks a lot.

Yuriy Rusinov
  • 61
  • 2
  • 5
  • Answer is here https://stackoverflow.com/questions/24295876/cmake-cannot-find-a-googletest-required-library – 273K Mar 05 '18 at 15:28
  • Thanks a lot. I forgot copy libraries into target directory. – Yuriy Rusinov Mar 05 '18 at 15:34
  • 3
    Not directly related to your question, but be careful using assertions and floating-point numbers. your `SquareRootTest` should be using the [appropriate assertions for floating-point numbers](https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#floating-point-comparison). – Arda Aytekin Mar 05 '18 at 15:36

0 Answers0