c++ - 运行第一个 gtest 示例时出现问题
问题描述
我安装了googletest
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
make install
如此处所述。我现在正在尝试编译以下代码
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
用g++ --std=c++17 gt.cpp -o gt
( g++ (GCC) version 10.2.0
),我得到
gt.cpp:1:10: fatal error: gtest/gtest.h: No such file or directory
1 | #include <gtest/gtest.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
似乎缺少包含路径,但我不知道该放入哪个路径。
clang++ -std=c++17 gt.cpp -o gt
,我得到
Undefined symbols for architecture x86_64:
"testing::InitGoogleTest(int*, char**)", referenced from:
_main in gt-7a908b.o
"testing::UnitTest::GetInstance()", referenced from:
RUN_ALL_TESTS() in gt-7a908b.o
"testing::UnitTest::Run()", referenced from:
RUN_ALL_TESTS() in gt-7a908b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
仅供参考,我不是 MACOS 11.6。
解决方案
推荐阅读
- python - Python 整数函数
- pandas - Pandas 多标准中的样式
- oracle - 在 PLSQL 中使用查询生成 CSV 文件
- android - Android Studio 不会警告 newapi。为什么?
- r - 在网站内抓取表格 - 如何从元素中找到表格?
- html - 宽度属性可接受的单位是什么?
- java - 如何获取具有继承的 main 方法的类的名称?
- apache-spark - Apache pyspark 删除停用词并计算
- javascript - 当我从 git 克隆代码并在机器上运行 npm install 时,错误是这样的。请帮我
- python - 如何在 Selenium Python 中访问 Span 类或元素