1. 程式人生 > >Google Test 配置使用

Google Test 配置使用

1、下載Google test框架

在本機git clone https://github.com/google/googletest.git

然後進入googletest/googletest/目錄(兩層),然後執行下面兩條命令編譯google test

# g++ -isystem ./include -I./ -pthread -c ./src/gtest-all.cc
   
# ar -rv libgtest.a gtest-all.o

2、 使用google test

在本機任意位置建立test.cpp,編譯的時候使用如下命令編譯程式

g++ -isystem (google test's path)/include -pthread test.cpp \
      (gtest's path)/libgtest.a -o binary_program

例如

g++ -isystem ~/googletest/googletest/include -pthread test.cpp \         
     ~/googletest/googletest/libgtest.a -o test_gtest

最終直接執行./test_gtest即可

3、這裡也可以建立一個CMakeLists.txt,使用cmake來簡化編譯過程