源码安装
1.github上下载源码
git clone https://github.com/google/googletest.git
2.源码编译
ubuntu@ubuntu:~$ cd googletest
ubuntu@ubuntu:~/googletest$ mkdir build
ubuntu@ubuntu:~/googletest/build$ cd build
ubuntu@ubuntu:~/googletest/build$ cmake ..
ubuntu@ubuntu:~/googletest/build$ make -j
报错
源码编译居然会报错。。。
仔细检查第一条错误,原来需要用c++11的标准来编译代码。
打开googletest文件夹里面的CMakeLists.txt
在里面新增这一行
add_definitions(-std=c++11)
此时CMakeLists.txt为:
# Note: CMake support is community-based. The maintainers do not use CMake
# internally.
cmake_minimum_required(VERSION 2.8.12)
add_definitions(-std=c++11) #########把这行加进去#################
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)
project(googletest-distribution)
set(GOOGLETEST_VERSION 1.10.0)
if (CMAKE_VERSION VERSION_GREATER "3.0.2")
if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endif()
enable_testing()
include(CMakeDependentOption)
include(GNUInstallDirs)
#Note that googlemock target already builds googletest
option(BUILD_GMOCK "Builds the googlemock subproject" ON)
option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON)
if(BUILD_GMOCK)
add_subdirectory( googlemock )
else()
add_subdirectory( googletest )
endif()
修改完成之和,再进行编译。
ubuntu@ubuntu:~/googletest/build$ cmake ..
ubuntu@ubuntu:~/googletest/build$ make -j
ubuntu@ubuntu:~/googletest/build$ sudo make install
安装完成
3. 如果出现找不到library
ld: error: unable to find library -lgtest_main
ld: error: unable to find library -lgtest
将生成的libgtest.a和libgtest_main.a拷贝到系统的lib路径下
sudo cp libgtest*.a /usr/local/lib
or
sudo cp libgtest*.a /usr/lib
参考链接:
Ubuntu下安装编译googletest,并进行调用测试_hsy12342611的博客-CSDN博客_googletest编译
Ubuntu 16.04安装gtest遇坑,成功安装及使用记录_Let'sCode的博客-CSDN博客
Ubuntu下GTest的安装和简单测试_权艺的博客-CSDN博客_ubuntu安装gtest