gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:43:35 24 4
gpt4 key购买 nike

我在 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,我会收到更多链接器错误)。

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

最佳答案

确保您不会不小心将自己的 gtest 与 ubuntu 附带的 gtest 混用。

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

关于c++ - 无法使用 ubuntu 运行 googletest(链接器错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24888198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com