ubuntu下googletest安装教程及报错解决办法

Googletest安装流程

1、从官网下载ubuntu下安装的source文件,下载链接为:
https://github.com/google/googletest.git
2、解压之后,cd到对应目录中,然后使用cmake进行编译,再进行make生成两个静态库libgtest.a libgtest_main.a,操作流程为:

cd ~/software/googletest-master
mkdir build
cd build
cmake ../googletest/
make

3、将步骤2中生成的两个库文件及/googletest/include/gtest文件,复制到用户目录下,操作如下:

sudo cp libgtest*.a  /usr/lib 
sudo cp -a /home/bruce/software/googletest-master/googletest/include/gtest /usr/include

至此Googletest就已经安装完成。

Googletest在make时报错

error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.


cc1plus: all warnings being treated as errors
CMakeFiles/gtest.dir/build.make:62: recipe for target ‘CMakeFiles/gtest.dir/src/gtest-all.cc.o’ failed
make[2]: *** [CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 1
CMakeFiles/Makefile2:104: recipe for target ‘CMakeFiles/gtest.dir/all’ failed
make[1]: *** [CMakeFiles/gtest.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
解决办法:
在安装包的googletest文件夹下(/home/bruce/software/googletest-master/googletest)找到CmakeLists.txt, 在其中添加如下语句:

SET(CMAKE_CXX_FLAGS "-std=c++0x")

再次make,便可以成功!


版权声明:本文为weixin_44401286原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。