1.下载gtest,release-1.8.0
git clone https://github.com/google/googletest
2.编译
cd googletest
mkdir build
cd build
cmake ..
make
出现以下错误:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
^
In file included from /home/liuzy/library/googletest/googletest/include/gtest/internal/gtest-internal.h:40:0,
from /home/liuzy/library/googletest/googletest/include/gtest/gtest.h:62,
from /home/liuzy/library/googletest/googletest/src/gtest-all.cc:38:
/home/liuzy/library/googletest/googletest/include/gtest/internal/gtest-port.h:985:1: error: identifier ‘nullptr’ is a keyword in C++11 [-Werror=c++0x-compat]
inline void FlushInfoLog() { fflush(nullptr); }
仔细阅读错误内容,会发现要选择相应的编译环境,即打开googletest/CMakeLists.txt
添加以下行:
add_definitions(-std=c++11)
再make就好了。
最后
sudo make install
本文详细介绍了在编译gtest过程中遇到的与C++11标准兼容性相关的问题,并提供了具体的解决方案,通过在CMakeLists.txt中添加-std=c++11选项来解决编译错误。
1万+

被折叠的 条评论
为什么被折叠?



