首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

MinGW+CMake编译Google Test疏失

2012-10-17 
MinGW+CMake编译Google Test出错下面是编译Google Test时出现的错误,那位帮忙看看是怎么错了。我的环境是Wi

MinGW+CMake编译Google Test出错
下面是编译Google Test时出现的错误,那位帮忙看看是怎么错了。
我的环境是Winxp+MinGW+CMake


NPP_EXEC: "make"
CD: f:\cmakework\gtest\build
Current directory: F:\cmakework\gtest\build
mingw32-make
Process started >>>
Scanning dependencies of target gtest
[ 50%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from f:\cmakework\gtest\include/gtest/internal/gtest-internal.h:40:0,
  from f:\cmakework\gtest\include/gtest/gtest.h:57,
  from f:\cmakework\gtest\src\gtest-all.cc:39:
f:\cmakework\gtest\include/gtest/internal/gtest-port.h: In function 'void testing::internal::SleepMilliseconds(int)':
f:\cmakework\gtest\include/gtest/internal/gtest-port.h:1076:24: error: 'nanosleep' was not declared in this scope
f:\cmakework\gtest\include/gtest/internal/gtest-port.h: In member function 'void testing::internal::MutexBase::Unlock()':
f:\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'
f:\cmakework\gtest\include/gtest/internal/gtest-port.h:1217:14: note: candidate is:
C:\MinGW\include/pthread.h:583:3: note: ptw32_handle_t& ptw32_handle_t::operator=(const ptw32_handle_t&)
C:\MinGW\include/pthread.h:583:3: note: no known conversion for argument 1 from 'int' to 'const ptw32_handle_t&'
f:\cmakework\gtest\include/gtest/internal/gtest-port.h: In member function 'void testing::internal::MutexBase::AssertHeld() const':
f:\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()'
f:\cmakework\gtest\include/gtest/internal/gtest-port.h:1224:5: note: candidate is:
C:\MinGW\include/objbase.h:78:13: note: BOOL operator==(const GUID&, const GUID&)
C:\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&}'
f:\cmakework\gtest\include/gtest/internal/gtest-port.h: In constructor 'testing::internal::Mutex::Mutex()':
f:\cmakework\gtest\include/gtest/internal/gtest-port.h:1252:14: error: no match for 'operator=' in '((testing::internal::Mutex*)this)->testing::internal::Mutex::<anonymous>.testing::internal::MutexBase::owner_ = 0'
f:\cmakework\gtest\include/gtest/internal/gtest-port.h:1252:14: note: candidate is:
C:\MinGW\include/pthread.h:583:3: note: ptw32_handle_t& ptw32_handle_t::operator=(const ptw32_handle_t&)
C:\MinGW\include/pthread.h:583:3: note: no known conversion for argument 1 from 'int' to 'const ptw32_handle_t&'
In file included from f:\cmakework\gtest\src\gtest-all.cc:42:0:
f:\cmakework\gtest/src/gtest.cc: At global scope:
f:\cmakework\gtest/src/gtest.cc:363:1: warning: missing braces around initializer for 'pthread_t {aka ptw32_handle_t}' [-Wmissing-braces]
f:\cmakework\gtest/src/gtest.cc:363:1: warning: missing initializer for member 'ptw32_handle_t::x' [-Wmissing-field-initializers]
mingw32-make[2]: *** [CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
mingw32-make[1]: *** [CMakeFiles/gtest.dir/all] Error 2
mingw32-make: *** [all] Error 2
<<< Process finished.
================ READY ================


[解决办法]
这是因为它只是检测的pthread.h中的pthread_create

核心错误提示是 f:\cmakework\gtest\include/gtest/internal/gtest-port.h:1076:24: error: 'nanosleep' was not declared in this scope

而你自带的pthread却没有nanosleep的实现,估计你使用的是pthread windows本地实现,不是posix thread实现

现在在windows上与posix thread匹配度很高的就2个
cygwin以及winpthreads

我一般使用后者。MinGW64 CRT构建出的gcc一般都带(如果不是乱编译的),同时gcc启用posix thread支持,而不是win32 thread支持。

当然你可以自行实现nanosleep



其他语法错误不知,先解决这个吧

热点排行