Google Test 配置使用

https://github.com/google/googletest/blob/master/googletest/README.md

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

参考:https://blog.csdn.net/qq_35976351/article/details/79634857 (test.cpp)

在本机任意位置创建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来简化编译过程

展开阅读全文

MinGW+CMake编译Google Test出错

04-19

下面是编译Google Test时出现的错误,那位帮忙看看是怎么错了。rn我的环境是Winxp+MinGW+CMakernrnrnNPP_EXEC: "make"rnCD: f:\cmakework\gtest\buildrnCurrent directory: F:\cmakework\gtest\buildrnmingw32-makernProcess started >>>rnScanning dependencies of target gtestrn[ 50%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.objrnIn file included from f:\cmakework\gtest\include/gtest/internal/gtest-internal.h:40:0,rn from f:\cmakework\gtest\include/gtest/gtest.h:57,rn from f:\cmakework\gtest\src\gtest-all.cc:39:rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h: In function 'void testing::internal::SleepMilliseconds(int)':rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h:1076:24: error: 'nanosleep' was not declared in this scopernf:\cmakework\gtest\include/gtest/internal/gtest-port.h: In member function 'void testing::internal::MutexBase::Unlock()':rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h:1217:14: error: no match for 'operator=' in '((testing::internal::MutexBase*)this)->testing::internal::MutexBase::owner_ = 0'rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h:1217:14: note: candidate is:rnC:\MinGW\include/pthread.h:583:3: note: ptw32_handle_t& ptw32_handle_t::operator=(const ptw32_handle_t&)rnC:\MinGW\include/pthread.h:583:3: note: no known conversion for argument 1 from 'int' to 'const ptw32_handle_t&'rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h: In member function 'void testing::internal::MutexBase::AssertHeld() const':rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h:1224:5: error: no match for 'operator==' in '((const testing::internal::MutexBase*)this)->testing::internal::MutexBase::owner_ == pthread_self()'rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h:1224:5: note: candidate is:rnC:\MinGW\include/objbase.h:78:13: note: BOOL operator==(const GUID&, const GUID&)rnC:\MinGW\include/objbase.h:78:13: note: no known conversion for argument 1 from 'const pthread_t aka const ptw32_handle_t' to 'const GUID& aka const _GUID&'rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h: In constructor 'testing::internal::Mutex::Mutex()':rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h:1252:14: error: no match for 'operator=' in '((testing::internal::Mutex*)this)->testing::internal::Mutex::.testing::internal::MutexBase::owner_ = 0'rnf:\cmakework\gtest\include/gtest/internal/gtest-port.h:1252:14: note: candidate is:rnC:\MinGW\include/pthread.h:583:3: note: ptw32_handle_t& ptw32_handle_t::operator=(const ptw32_handle_t&)rnC:\MinGW\include/pthread.h:583:3: note: no known conversion for argument 1 from 'int' to 'const ptw32_handle_t&'rnIn file included from f:\cmakework\gtest\src\gtest-all.cc:42:0:rnf:\cmakework\gtest/src/gtest.cc: At global scope:rnf:\cmakework\gtest/src/gtest.cc:363:1: warning: missing braces around initializer for 'pthread_t aka ptw32_handle_t' [-Wmissing-braces]rnf:\cmakework\gtest/src/gtest.cc:363:1: warning: missing initializer for member 'ptw32_handle_t::x' [-Wmissing-field-initializers]rnmingw32-make[2]: *** [CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1rnmingw32-make[1]: *** [CMakeFiles/gtest.dir/all] Error 2rnmingw32-make: *** [all] Error 2rn<<< Process finished.rn================ READY ================rn 论坛

没有更多推荐了,返回首页