无法使用ubuntu运行googletest(链接器错误)

时间:2014-07-22 13:03:35

标签: c++ gcc linker eclipse-cdt googletest

我在linux下使用make构建了googletest,生成的文件是libgtest.a libgtest_main.a。

我从我的应用程序中引用了包含文件,并添加了以下lib依赖项(按给定的顺序):

-lgtest
-lpthread

但是当我尝试编译时,我收到以下两个链接器错误:

more undefined references to `testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)

undefined reference to `testing::internal::String::ShowCStringQuoted(char const*)

根据我在googletest源代码中看到的内容,EqFailure功能直接在gtest.cc中实现。我不明白为什么我应该在这里得到链接器错误,googletest的其他定义显然也可以找到(如果我删除-lgtest,我会收到很多链接器错误)。

我错过了什么?提前谢谢。

1 个答案:

答案 0 :(得分:2)

请确保您不会意外地混合您自己的gtest和ubuntu附带的gtest。

我使用cmake构建并得到相同的错误,因为cmake选择了/ usr / include而不是我自己定制的版本(这是我链接的)。