I'm trying to compile a very simple program using Boost Test Unit
#define BOOST_TEST_MODULE My Test
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(first_test) { int i = 1; BOOST_CHECK(i == 1); }
If I compile this small program with no parameters,
g++ test1.cpp
there's no problem. But, if I try to use C++11 standard,
g++ test1.cpp -std=c++11
I get some errors:
In file included from /usr/include/boost/test/included/unit_test.hpp:19:0,
from test1.cpp:2: /usr/include/boost/test/impl/debug.ipp: En la función ‘const char* boost::debug::{anónimo}::prepare_gdb_cmnd_file(const boost::debug::dbg_startup_info&)’: /usr/include/boost/test/impl/debug.ipp:426:23: error: ‘::mkstemp’ no se ha declarado
fd_holder cmd_fd( ::mkstemp( cmd_file_name ) );
^ In file included from /usr/include/boost/test/included/unit_test.hpp:19:0,
from test1.cpp:2: /usr/include/boost/test/impl/debug.ipp: En la función ‘bool boost::debug::attach_debugger(bool)’: /usr/include/boost/test/impl/debug.ipp:863:34: error: ‘::mkstemp’ no se ha declarado
fd_holder init_done_lock_fd( ::mkstemp( init_done_lock_fn ) );
^ In file included from /usr/include/boost/test/utils/runtime/cla/dual_name_parameter.hpp:19:0,
from /usr/include/boost/test/impl/unit_test_parameters.ipp:31,
from /usr/include/boost/test/included/unit_test.hpp:33,
from test1.cpp:2: /usr/include/boost/test/utils/runtime/config.hpp: En la función ‘void boost::runtime::putenv_impl(boost::runtime::cstring, boost::runtime::cstring)’: /usr/include/boost/test/utils/runtime/config.hpp:95:51: error: ‘putenv’ no se declaró en este ámbito
putenv( const_cast<char*>( fs.str().c_str() ) );
(The compiler is in spanish)
I'm using:
Cygwin 64 bits
Cygwin's Boost 1.59
Cygwin's G++ 4.9.3
Any help will be welcome. Thanks. José.-
Looks like it is a Cygwin thing. I could not reproduce it on OpenSUSE 13.2 i586 with Boost 1.54, but got the same result as yours on Cygwin Win32 with Boost 1.57. And, as Bo Persson suggested, also tried std=gnu+11
.
As the compiler sayd “not declared” — even if you explicitly include <stdlib.h>
which declares both mkstemp
and putenv
, — it seemed doubtful to me that it was all about C++ language extensions, but rather more like header file issue. Indeed, in Linux we have:
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED \
|| defined __USE_XOPEN2K8
# ifndef __USE_FILE_OFFSET64
extern int mkstemp (char *__template) __nonnull ((1)) __wur;
# else
# ifdef __REDIRECT
extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
__nonnull ((1)) __wur;
# else
# define mkstemp mkstemp64
# endif
# endif
# ifdef __USE_LARGEFILE64
extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
# endif
#endif
But in Cygwin:
#ifndef __STRICT_ANSI__
#ifndef _REENT_ONLY
int _EXFUN(mkstemp,(char *));
#endif
int _EXFUN(_mkstemp_r, (struct _reent *, char *));
#endif
Then I added a couple of #undef
s to your program:
#undef __STRICT_ANSI__
#undef _REENT_ONLY
#define BOOST_TEST_MODULE My Test
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(first_test) { int i = 1; BOOST_CHECK(i == 1); }
And could compile it fine with std=c++11
. I have no idea how incorrect and stupid this may be, but at least it produced very similar exe file that only differs by 20 bytes (aside from fingerprint).