windows系统上安装配置google benchmark

google benchmark主要是对c++中的函数进行基准功能测试的库,它需要自己安装。

可以测试代码的性能。

经过两天的努力,终于在windows上配置成功。

下载地址:

  github:https://github.com/google/benchmark

  gitee:https://gitee.com/mirrors/google-benchmark

安装步骤:(官方复制过来的,该步骤本没有错)

 1 # Check out the library.
 2 $ git clone https://github.com/google/benchmark.git
 3 # Go to the library root directory
 4 $ cd benchmark
 5 # Make a build directory to place the build output.
 6 $ cmake -E make_directory "build"
 7 # Generate build system files with cmake, and download any dependencies.
 8 $ cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
 9 # or, starting with CMake 3.13, use a simpler form:
10 # cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
11 # Build the library.
12 $ cmake --build "build" --config Release

我遇到的问题:

  由于是直接在github上下载下来的 它后面的test什么的都会从github上下载,从而导致有些东西可能下载不完全,所以每次

cmake --build "build" --config Release

的时候,总是会报错,对于这个问题的解决方法,就是使用gitee上的模板来下载。(我是按照下面的步骤来安装成功的)
 1 # Check out the library.
 2 $ git clone https://gitee.com/mirrors/google-benchmark.git
 3 # Go to the library root directory
 4 $ cd benchmark
 5 # Make a build directory to place the build output.
 6 $ cmake -E make_directory "build"
 7 # Generate build system files with cmake, and download any dependencies.
 8 $ cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
 9 # or, starting with CMake 3.13, use a simpler form:
10 # cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
11 # Build the library.
12 $ cmake --build "build" --config Release

安装好之后,可以按照官方文档配置全局变量,即可使用。

因为我使用的是clion编译器,同时配合cmake,所以要在CMakeLists.txt里面添加一些配置。(该配置官方文档里面有)

如果你也使用了cmake,切记 

target_link_libraries
一定要写在配置文件的最后面!!!

样例:

  

 

 

 

 


posted @ 2022-08-30 15:22  莴苣&  阅读(717)  评论(1编辑  收藏  举报