linking error when building Google test on mac (commandline)

前端 未结 3 1727
梦谈多话
梦谈多话 2020-12-15 07:53

I am currently trying to build some test code that uses Google C++ Test framework but I keep getting an error stating

ld: warning: in /usr/local/lib/libgtest.dylib,

相关标签:
3条回答
  • 2020-12-15 08:46

    Solution found. It turns out that the build instructions used are correct the issue was that on the computer that the build was being performed another developer had done some work with Google Test Framework 1.5 and they had installed the libraries on the computer in the compilers search path. This resulted in the compiler finding the other library first that was not compiled using multiple architecture options.

    0 讨论(0)
  • 2020-12-15 08:53

    You might also have this problem if gmock and gtest are out of sync. I had similar build errors with gmock-1.6.0 and gtest-1.7.0:

    ../../../third_party/gmock/build/libgmock.a(gmock-all.cc.o): In function `testing::internal::ParseGoogleMockFlagValue(char const*, char const*, bool)':
    gmock-all.cc:(.text+0x3b5c): undefined reference to `testing::internal::String::Format(char const*, ...)'
    ../../../third_party/gmock/build/libgmock.a(gmock-all.cc.o): In function `testing::internal::String::operator==(char const*) const':
    gmock-all.cc:(.text._ZNK7testing8internal6StringeqEPKc[testing::internal::String::operator==(char const*) const]+0x33): undefined reference to `testing::internal::String::Compare(testing::internal::String const&) const'
    collect2: ld returned 1 exit status
    

    Switching to both 1.7.0 or both 1.6.0 fixed the problem.

    0 讨论(0)
  • 2020-12-15 08:54

    Compile gtest and your project with the same compiler (-flags).

    If you compiled gtest with Apple g++ and meanwhile installed gcc with e.g. homebrew, linking to gtest will cause this error. This is exactly the reason why Google advices to integrate gtest statically linked in your project, and not to use precompiled binaries.

    0 讨论(0)
提交回复
热议问题