一、安装Gtest
1、下载最新版gtest源码
git clone https://github.com/google/googletest
cd googletest/googletest
2、编辑CMakeLists.txt文件,将option(BUILD_SHARED_LIBS “Build shared libraries (DLLs).” OFF)中的OFF改为ON
3、编译(需要安装cmake)
cmake CMakeLists.txt
make
我使用的是Ubuntu16.04,这里遇到了错误“this file requires compiler and library support for the iso c++ 2011 standard”。解决方法:在CMakeLists.txt中添加一句
SET( CMAKE_CXX_FLAGS "-std=c++11 -O3")
并且在之后编译gtest文件的时候采用如下方式编译,问题解决
g++ -std=c++11 your_file.cpp -o main
4、make成功后生成了两个静态库文件,libgtest_main.so和libgtest.so,将它们拷贝到/usr/local/lib/目录下,并执行ldconfig