无法让谷歌测试与 ubuntu 一起运行(链接器错误)

Can't get googletest running with ubuntu (linker errors)

本文关键字:运行 链接 错误 一起 ubuntu 谷歌 测试      更新时间:2023-10-16

我已经在linux下使用make构建了googletest,结果文件是libgtest。libgtest_main.a。

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

-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,我得到更多的链接错误)。

我错过了什么?

确保你不会不小心把你自己的gtest和ubuntu附带的gtest混在一起。

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