Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CMake tutorial gmock 1.7 errors
┌─[getchell][Hapkido][±][master ✓][~/cmake-tutorial]
└─▪ mkdir build
┌─[getchell][Hapkido][±][master ✓][~/cmake-tutorial]
└─▪ cd build
┌─[getchell][Hapkido][±][master ✓][~/cmake-tutorial/build]
└─▪ cmake -G "Unix Makefiles" ..
-- The C compiler identification is AppleClang
-- The CXX compiler identification is AppleClang
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found PythonInterp: /usr/bin/python (found version "2.7.6")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/getchell/cmake-tutorial/build
┌─[getchell][Hapkido][±][master ✓][~/cmake-tutorial/build]
└─▪ make
Scanning dependencies of target toDoCore
[ 10%] Building CXX object ToDoCore/CMakeFiles/toDoCore.dir/ToDo.cpp.o
Linking CXX static library libtoDoCore.a
[ 10%] Built target toDoCore
Scanning dependencies of target toDo
[ 20%] Building CXX object CMakeFiles/toDo.dir/main.cpp.o
Linking CXX executable toDo
[ 20%] Built target toDo
Scanning dependencies of target gmock_main
[ 30%] Building CXX object gmock/CMakeFiles/gmock_main.dir/gtest/src/
In file included from /Users/getchell/gmock-1.7.0/gtest/src/
/Users/getchell/gmock-1.7.0/gtest/src/ error: missing field
'owner_' initializer [-Werror,-Wmissing-field-initializers]
/Users/getchell/gmock-1.7.0/gtest/include/gtest/internal/gtest-port.h:1390:79: note:
expanded from macro 'GTEST_DEFINE_STATIC_MUTEX_'
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
1 error generated.
make[2]: *** [gmock/CMakeFiles/gmock_main.dir/gtest/src/] Error 1
make[1]: *** [gmock/CMakeFiles/gmock_main.dir/all] Error 2
make: *** [all] Error 2
Copy link

j3lamp commented Sep 19, 2014

So this is the problem with using libraries and building with relatively strict warnings and treating warnings as errors. I knew I had used GMock 1.7.0 on OS X successfully before. In that case I actually edited the two include_directories() commands, one each in GTest and GMock, to start with the SYSTEM argument, which tells GCC and Clang to ignore warnings from those headers. The other option is to disable warnings altogether for the GMock and GTest targets. In fact I had solved this with GMock 1.6.0 with the following line:


Unfortunately to fix a problem so that you could link gmock or gmock_main in as a DLL in GMock 1.7.0 gmock no longer links against gtest instead the GTest source is compiled directly in, same thing with gmock_main. So if you replace the above line with

set_property(TARGET gtest gmock gmock_main APPEND_STRING PROPERTY COMPILE_FLAGS " -w")

then it should build again. The fun of upgrading, no?

Copy link

binshuohu commented Feb 14, 2015

This certainly solves my problem, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment