【C++】GTEST && google/benchmark工具安装

本文记录了在C++项目中集成GTEST和google/benchmark的安装过程。通过在项目根目录执行特定命令,可自动完成gtest和benchmark的安装。文章提到了CMakeList.txt的配置,并指出有重复安装的情况,建议后期优化。同时,简述了CMakeList.txt的一些基本知识。
摘要由CSDN通过智能技术生成

最近在做一些C++相关事情,用的是C++编译成so库,最后引入到android播放器当中的,为了对C++代码进行快速迭代以及做性能测试,准备引入GTEST一个google出品的C++测试库,以及google/benchmark库用来做性能测试

注:其实按照google benchmark在github页面的安装教程来就可以了,这篇文章只是做一个简单的更新,算是一个安装笔记

google benchmark依赖gtest,所以正常安装google benchmark之后,会自动安装gtest

安装

  1. 在项目的根目录下面执行下面的命令,会在根目录下面生成一个benchmark目录
# Check out the library.
# Benchmark requires Google Test as a dependency. Add the source tree as a subdirectory.
git clone https://github.com/google/benchmark.git
git clone https://github.com/google/googletest.git benchmark/googletest
# Go to the library root directory
cd benchmark
cmake -E make_directory "build"
# cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../
# or, starting with CMake 3.13, use a simpler form:
cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
cmake --build "build" --config Release

# check install
# cmake -E chdir "build" ctest --build-config Release
# install global
# sudo cmake --build "build" --config Release --target install
  1. CMakeList.txt中的引用
cmake_minimum_required(VERSION 3.19)
project(leetcode)
set(CMAKE_CXX_STANDARD 14)

add_subdirectory(benchmark)

# benchmark
set(BENCHMARK_SRC
        bench_test.cpp)
add_executable(bench ${
   BENCHMARK_SRC})
target_link_libraries(bench benchmark benchmark_main pthread gtest_main)
# 用来引入头文件
# target_include_directories()

# gtest
add_executable(lgtest main_gtest.cpp)
target_link_libraries(lgtest gtest_ma
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值