undefined reference to testing::internal::EqFailure in gtest

I've had exactly this error message in the following scenario:

Using a messy Ubuntu 14.10 (which has a mismatch between libgtest-dev (GTest 1.6), and google-mock (GMock 1.7 with bundled GTest 1.7), I chose the wrong path - installed GMock 1.6, to match the system's libgtest-dev).

For some time the project compiled, but then - after a git pull, some new features of 1.7 were used and I needed to upgrade to 1.7. I installed it from google-mock package (rebuilt with CMake, then copied to /usr/include and /usr/lib). Then, I launched the build, and the gtest.h:1337 (isn't this line number telling?) linker error started happening.

After hours of inspecting the libs with nm -C libgtest.a (repeat for libgtest_main.a, libgmock.a and libgmock_main.a), I found that the testing::internal::EqFailure function takes 2x std::string, and not testing::internal::String.!!

I checked the headers - nothing there - std::string everywhere. Where was the strange reference?

Well - it was in the old object files, build with GTest 1.6 headers! So now:

TL;DR

  • Remove and rebuild all old objects which you built with GTest 1.6 headers. (make clean, or something to that effect, YMMV)
  • Upgrade GMock, if you haven't.
  • Use only bundled GTest (from GMock), if you haven't.

Probably this is less likely to be the problem compared with the accepted solution, but in my case I was getting the same error as the OP due to using g++-5 to compile gtest vs. g++-4.8 on the project which I was trying to compile, which resulted in symbols not being found.

If the accepted answer doesn't work for you then you should probably double check that you have used the same compiler for your project as gtest.


Here I provide another case that may possible be a reason for such a link error:

In my project, for some compatibility reason I have to compile my project with a macro "-D_GLIBCXX_USE_CXX11_ABI=0", which forces the compiler to use old C++11 ABI for compilation(in GCC>5.0). However, the gtest library used was compiled before, and was just compiled directly without this option.

And finally i got a similar error but the function signature of testing::internal::EqFailure is like "testing::internal::EqFailure(char const*, char const*, std::__cxx11::string const&, std::__cxx11::string const&, bool)". I don't quite remember the exact signature but there was something like "__cxx11" in the string args rather than std::string. And when I found it I figured out that this may caused by that macro I used.

So this problem was finally solved by recompiling the gtest with "-D_GLIBCXX_USE_CXX11_ABI=0" and then link the new library.

Hope this answer may help for someone.