下载
下载地址为https://github.com/google/googletest/tags,以版本release-1.10.0 的tar.gz 包为例,下载完成后的文件为 googletest-release-1.10.0.tar.gz 。
安装
googletest使用CMake来进行构建。
使用命令tar -zxvf googletest-release-1.10.0.tar.gz 解压缩,解压缩完成后,目录googletest-release-1.10.0结构如下:
[root@instance-1apocjsh googletest-release-1.10.0]
.
├── appveyor.yml
├── BUILD.bazel
├── ci
├── CMakeLists.txt
├── CONTRIBUTING.md
├── googlemock
├── googletest
├── library.json
├── LICENSE
├── platformio.ini
├── README.md
└── WORKSPACE
使用命令mkdir build 创建构建目录,然后进入build(命令cd build ),使用命令build ../googletest 构建Makefile,
[root@instance-1apocjsh build]
CMake Warning at CMakeLists.txt:57 (project):
VERSION keyword not followed by a value or was followed by a value that
expanded to nothing.
-- The CXX compiler identification is GNU 4.8.5
-- The C compiler identification is GNU 4.8.5
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
CMake Deprecation Warning at CMakeLists.txt:59 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- Found PythonInterp: /usr/bin/python (found version "2.7.5")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /root/googletest-release-1.10.0/build
然后使用命令make -j8 进行编译。
[root@instance-1apocjsh build]
[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 50%] Linking CXX static library lib/libgtest.a
[ 50%] Built target gtest
[ 75%] Building CXX object CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library lib/libgtest_main.a
[100%] Built target gtest_main
注意,如果编译有报错,需要指定使用C++11语法进行编译, 修改googletest/CMakeLists.txt ,在其中添加使用C++11语法的命令set (CMAKE_CXX_STANDARD 11) ,再重新进行操作。
编译完成后,生成的静态库文件位于build/lib 中,头文件位于googletest/include 中。 将静态库和头文件一起整理放到新文件夹googletest中,方便使用。googletest目录结构如下:
[root@instance-1apocjsh googletest]
.
├── include
│ └── gtest
│ ├── gtest-death-test.h
│ ├── gtest.h
│ ├── gtest-matchers.h
│ ├── gtest-message.h
│ ├── gtest-param-test.h
│ ├── gtest_pred_impl.h
│ ├── gtest-printers.h
│ ├── gtest_prod.h
│ ├── gtest-spi.h
│ ├── gtest-test-part.h
│ ├── gtest-typed-test.h
│ └── internal
│ ├── custom
│ │ ├── gtest.h
│ │ ├── gtest-port.h
│ │ ├── gtest-printers.h
│ │ └── README.md
│ ├── gtest-death-test-internal.h
│ ├── gtest-filepath.h
│ ├── gtest-internal.h
│ ├── gtest-param-util.h
│ ├── gtest-port-arch.h
│ ├── gtest-port.h
│ ├── gtest-string.h
│ ├── gtest-type-util.h
│ └── gtest-type-util.h.pump
└── lib
├── libgtest.a
└── libgtest_main.a
5 directories, 26 files
参考
googletest安装与使用 GoogleTest测试框架介绍(一) GoogleTest测试框架介绍(二)
|