gtest 編譯安裝

2022-07-31 01:33:15 字數 2087 閱讀 8355

第一步:獲取原始碼

git clone 

第二步:安裝cmake工具

yum install cmake

第三步:配置

cd googletest

配置工程:cmake.

編譯:生成靜態庫

[root@xuperior-pc googletest]#make

[ 25%] linking cxx static library ../lib/libgtest.a

[ 50%] linking cxx static library ../lib/libgmock.a

[ 75%] linking cxx static library ../lib/libgmock_main.a

[100%] linking cxx static library ../lib/libgtest_main.a

編譯例子testcase:

cd googletest/samples/

g++ sample1.cc sample1_unittest.cc -lgtest -lgtest_main-lpthread -o test1 -l/home/xuperior/code/googletest/lib -i/home/xuperior/code/googletest/googletest/include

wait for a moment ......

./test1

[root@xuperior-pc samples]# ./test1

running main() from /home/xuperior/code/googletest/googletest/src/gtest_main.cc

[**********] running 6 tests from 2 test suites.

[----------] global test environment set-up.

[----------] 3 tests from factorialtest

[ run ] factorialtest.negative

[ ok ] factorialtest.negative (0 ms)

[ run ] factorialtest.zero

[ ok ] factorialtest.zero (0 ms)

[ run ] factorialtest.positive

[ ok ] factorialtest.positive (0 ms)

[----------] 3 tests from factorialtest (0 ms total)

[----------] 3 tests from isprimetest

[ run ] isprimetest.negative

[ ok ] isprimetest.negative (0 ms)

[ run ] isprimetest.trivial

[ ok ] isprimetest.trivial (0 ms)

[ run ] isprimetest.positive

[ ok ] isprimetest.positive (0 ms)

[----------] 3 tests from isprimetest (0 ms total)

[----------] global test environment tear-down

[**********] 6 tests from 2 test suites ran. (0 ms total)

[ passed ] 6 tests.

done!

ps : 如果你存在多個版本gcc,可能需要新增對應的libstdc++路徑到 ld_library_path, 不然會提示c++庫版低,用例無法執行。

gtest編譯鏈結錯誤

在mac上使用googletest編寫單元測試,不需要額外鏈結pthread。但是在linux上 github action的預設構建機器ubuntu20.04lts 上,編譯鏈結gtest 需要額外鏈結pthread,並且,需要注意的是,使用cmake構建時,gtest和pthread鏈結順序 需...

linux(ubuntu)下 gtest編譯安裝

berry berry unzip googletest master.zip berry berry googletest master mkdir build berry berry googletest master build cmake looking for pthread create...

gtest安裝及測試

git clonegtest編譯 cd googletest生成makefile檔案 先安裝cmake,brew install cmake cmake cmakelists.txt執行make,生成兩個靜態庫 libgtest.a libgtest main.a make拷貝到系統目錄,注意,如果...