GTEST 编译过程错误
GTEST安装以及简单使用指南
很多博客都写了关于GTEST的安装指南,其实过程并不复杂,但其中有一些坑还是想说一下。
1 正常安装过程
git clone http://github.com/google/googletest
cd googletest
mkdir build && cd build
cmake ..
make
make install
2 ⚠️注意点
- 安装gtest前确保安装了cmake
- 在安装过程中如果有出现一下错误
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 1
make[1]: *** [googletest/CMakeFiles/gtest.dir/all] Error 2
make: *** [all] Error 2
或者你应该可以看到,在上面的报错信息中有 xxx is a C++11 extenstion等等,请按如下代码进行编译,
git clone https://github.com/google/googletest.git
cd googletest
mkdir build
cd build
cmake -DCMAKE_CXX_COMPILER="c++" -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++" ../
make
sudo make install
如果上述代码依然失败,请删除 -stdlib=libc++ 该选项。我是在删除该选项之后成功的,OS为MacOS,ubuntu应该同理。
3 简单示例
使用googletest文件下的googletest文件夹中的sample进行简单的测试。
我把代码贴在这里吧,
// Copyright 2005, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials p

本文详细介绍了GTEST的安装及编译过程,特别强调了在MacOS和Ubuntu环境下解决常见错误的方法,并提供了一个简单的示例代码,帮助读者快速上手。
最低0.47元/天 解锁文章
8131

被折叠的 条评论
为什么被折叠?



