0

I installed googletest with

git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
make install

as explained here. I am now trying to compile the following code

#include <gtest/gtest.h>

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

With g++ --std=c++17 gt.cpp -o gt (g++ (GCC) version 10.2.0), I get

gt.cpp:1:10: fatal error: gtest/gtest.h: No such file or directory
    1 | #include <gtest/gtest.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.

Seems like an include path is missing but I don't know which one to put in.

With clang++ -std=c++17 gt.cpp -o gt, I get

Undefined symbols for architecture x86_64:
  "testing::InitGoogleTest(int*, char**)", referenced from:
      _main in gt-7a908b.o
  "testing::UnitTest::GetInstance()", referenced from:
      RUN_ALL_TESTS() in gt-7a908b.o
  "testing::UnitTest::Run()", referenced from:
      RUN_ALL_TESTS() in gt-7a908b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

FYI, I am not MACOS 11.6.

Remi.b
  • 16,247
  • 25
  • 74
  • 153

0 Answers0