dimanche 2 juillet 2017

gtest –– Undefined symbols when using TEST_F

I am not sure if I setup my gtest environment correctly. When I do plain TEST with EXPECT_EQ stuff, it's all good. However, when I try fancier stuff like TEST_F, the linker complains.

Source Code:

class MyTest : public testing::Test
{
protected:
    static const int my_int = 42;
};

TEST_F(MyTest, test)
{
    EXPECT_EQ(my_int, 42);
}

And this gives

Undefined symbols for architecture x86_64:
  "MyTest::my_int", referenced from:
      MyTest_test_Test::TestBody() in instruction_test.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [tests/tests/run_tests] Error 1
make[2]: *** [tests/tests/CMakeFiles/run_tests.dir/all] Error 2
make[1]: *** [tests/tests/CMakeFiles/run_tests.dir/rule] Error 2
make: *** [run_tests] Error 2

Any idea why this happens?

Aucun commentaire:

Enregistrer un commentaire