How to install GTest on Mac OS X with homebrew?

南楼画角 提交于 2019-12-02 22:33:13

If you want the latest version without using Homebrew:

git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
make install

For the question 'Why there is no repository for it?' see related gtest FAQ question. But you can create formula by yourself if you want - see this post for the details (but don't sure if it will work for 1.6).

But I suggest you just install gtest: read the readme for the detailed instructions. There are few simple steps:
Download and extract sources to some directory gtest_dir.
Build object files:

g++ -I$gtest_dir/include -I$gtest_dir -c $gtest_dir/src/gtest-all.cc
g++ -I$gtest_dir/include -I$gtest_dir -c $gtest_dir/src/gtest_main.cc

Link:

ar -rv libgtest.a gtest-all.o
ar -rv libgtest_main.a gtest_main.o


Note: if you want to build gtest with support of C++11 and libc++ you need to do some extra work:

You can use this:

brew install --HEAD https://gist.githubusercontent.com/Kronuz/96ac10fbd8472eb1e7566d740c4034f8/raw/gtest.rb

I just installed gtest using cmake and make. I can show you how did I install Google Test manually. It's not complicated, just following the steps.

  1. download the gtest file from https://github.com/google/googletest/archive/release-1.8.0.zip and unzip it.
  2. cd googletest-release-1.8.0/googletest/ mkdir bld cd bld cmake .. make cp -a ../include/gtest /usr/local/include cp -a *.a /usr/local/lib
  3. delete the folder googletest-release-1.8.0 and release-1.8.0.zip

If you want to use google-test please use #include <gtest/gtest.h>.

If you want to use Google Test version 1.7.0, just download the release-1.7.0.zip and in the 2. step use cd googletest-release-1.7.0 instead of cd googletest-release-1.8.0/googletest/. The rest steps are the same.

Enjoy it!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!