Mik*_*han 5

/home/me/googletest
https://github.com/google/googletest
./googletestCWDCWD/home/me/
CWD
$ mkdir googletest_build
$ cd googletest_build
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/home/me/googletest ../googletest
$ make
$ make install

在此之后,您会发现:-

/home/me/googletest/
                lib/
                    libgmock.a
                    libgmock_main.a
                    libgtest.a
                    libgtest_main.a
                include/
                        gmock/
                            # gmock header files
                        gtest/
                            # gtest header files

然后,您可以在源代码中使用 gtest/gmock 标头,例如:

#include <gtest/gtest.h>
#include <gmock/gmock.h>

并编译和链接一个 gtest/gmock 程序,如:

g++ -pthread -I/home/me/googletest/include -c -o my-unit-tester.o my-unit-tester.cpp
g++ -o my-unit-tester my-unit-tester.o -L/home/me/googletest/lib -lgtest -lgmock -pthread
-I...-L...
-pthread
CWD/googletestCWD/googletest_build
cmake