简体   繁体   English

CppuTest使用C ++ 11版本构建

[英]CppuTest to build with C++11 versions

Installed g++ 4.9.0 (experimental) version under Ubuntu (I am using certain features provided by this version) 在Ubuntu下安装了g++ 4.9.0 (实验)版本(我正在使用此版本提供的某些功能)

When building my code, I use cmake from a script, and it builds correctly. 在构建我的代码时,我使用脚本中的cmake ,并且它正确构建。 gcc below contains the path where g++ is installed (/mnt...) 下面的gcc包含安装g ++的路径(/ mnt ...)

$_cmake_ $_dir_ -DCMAKE_CXX_COMPILER=${_gpp_} -DCMAKE_C_COMPILER=${_gcc_} -DCMAKE_BUILD_TYPE=${_build_} -DCMAKE_INSTALL_PREFIX=${_install_} -DBUILD_TESTING:BOOL=1 

Now, when I make the CppuTest to build the Unit Tests for my code, I get the following error. 现在,当我使用CppuTest为我的代码构建单元测试时,我收到以下错误。

make all 
compiling UncrosserTest.cpp

In file included from /home/miguel/Desktop/Ugur/scmProject/scm/dist/dev/mfx_prod/scm/20160207/include/scm/services/primitives.hpp:4:0,
                 from /home/miguel/Desktop/Ugur/scmProject/log/lidya/src/cpp/scm/services/examples/dummy_strategy/Inside.hpp:6,
                 from AllTests/Uncrosser/UncrosserTest.cpp:7:
/usr/include/c++/4.9/experimental/optional: In member function ‘void std::experimental::_Optional_base<_Tp, _ShouldProvideDestructor>::_M_construct(_Args&& ...)’:
/usr/include/c++/4.9/experimental/optional:294:18: error: expected type-specifier
           ::new (std::__addressof(this->_M_payload))
                  ^
/usr/include/c++/4.9/experimental/optional:294:18: error: expected ‘)’
/usr/include/c++/4.9/experimental/optional: In member function ‘void std::experimental::_Optional_base<_Tp, false>::_M_construct(_Args&& ...)’:
/usr/include/c++/4.9/experimental/optional:424:18: error: expected type-specifier
           ::new (std::__addressof(this->_M_payload))
                  ^
/usr/include/c++/4.9/experimental/optional:424:18: error: expected ‘)’
make: *** [objs/AllTests/Uncrosser/UncrosserTest.o] Error 1

In the CppuTest makefile have included CPPUTEST_CPPFLAGS += -std=c++1y . 在CppuTest中,makefile包含了CPPUTEST_CPPFLAGS += -std=c++1y I guess that am missing some flags in this makefile because as I said the C++ experimental library is building correctly in my "regular" code. 我想这个makefile中缺少一些标志,因为我说C ++实验库正在我的“常规”代码中正确构建。 What am I missing ? 我错过了什么?

Possible it's an include problem, see CppUTest Manual - section Conflicts with operator new macros (STL!) and Conflicts with my own overload! 可能是包含问题,请参阅CppUTest手册 - 与操作员新宏冲突(STL!)与我自己的重载冲突!

TL;DR TL; DR

In UncrosserTest add includes for CppUTest after your's. UncrosserTest你的之后UncrosserTest添加包含。

Instead of 代替

#include <CppUTest/TestHarnes.h>
#include "whatever.h"

do

#include "whatever.h"
#include <CppUTest/TestHarnes.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM