Linux知识点(13)_安装编译gtest中遇到的坑

本文详细介绍了在编译gtest过程中遇到的与C++11标准兼容性相关的问题,并提供了具体的解决方案,通过在CMakeLists.txt中添加-std=c++11选项来解决编译错误。

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值