GTEST安装以及简单实例使用指南

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

GTEST 编译过程错误

GTEST安装以及简单使用指南

很多博客都写了关于GTEST的安装指南,其实过程并不复杂,但其中有一些坑还是想说一下。

1 正常安装过程

git clone http://github.com/google/googletest
cd googletest
mkdir build && cd build
cmake ..
make
make install

2 ⚠️注意点

  1. 安装gtest前确保安装了cmake
  2. 在安装过程中如果有出现一下错误
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值