2

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é.-

4

1 回答 1

3

看起来这是一个 Cygwin 的东西。我无法在带有 Boost 1.54 的 OpenSUSE 13.2 i586 上重现它,但在带有 Boost 1.57 的 Cygwin Win32 上得到了与您相同的结果。而且,正如Bo Persson建议的那样,也尝试过std=gnu+11

正如编译器所说的“未声明”——即使你明确地包含<stdlib.h>which 声明了mkstempputenv,——这对我来说似乎是关于 C++ 语言扩展的,而更像是头文件问题。事实上,在 Linux 中,我们有:

#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

但是在 Cygwin 中:

#ifndef __STRICT_ANSI__
#ifndef _REENT_ONLY
int _EXFUN(mkstemp,(char *));
#endif
int _EXFUN(_mkstemp_r, (struct _reent *, char *));
#endif

#undef然后我在你的程序中添加了几个s:

#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); }

并且可以用std=c++11. 我不知道这可能是多么不正确和愚蠢,但至少它产生了非常相似的exe文件,仅相差 20 个字节(除了指纹)。

于 2015-09-16T18:33:47.970 回答