2015-10-07 43 views
2

我编译两个升压库的版本 - 1.54和1.58相似:OS X铛C++ 11和libstdC++编译提升问题

$ mkdir build && ./bootstrap --prefix=$(pwd)/build 
$ ./b2 cxxflags="-stdlib=libstdc++" linkflags="-stdlib=libstdc++" && ./b2 install 

现在,我试图编译这个小应用:

#include <boost/asio.hpp> 
#include <boost/asio/steady_timer.hpp> 

boost::asio::io_service io_service_; 
boost::asio::steady_timer timer_(io_service_); 

int 
main() 
{ 
    return 0; 
} 

这样的: $克++ -c -std = GNU ++ 11 -stdlib = ++的libstdc -I的main.cpp

它完美地编译为升压1.54.0和给出误差(大于20),用于Boost 1.58.0:

boost_1_58_0/build/include/boost/asio/detail/addressof.hpp:31:12: error: no member named 'addressof' in namespace 'std' 
using std::addressof; 
boost_1_58_0/build/include/boost/asio/detail/handler_alloc_helpers.hpp:37:56: error: no member named 'addressof' in namespace 'boost::asio::detail' 
    return asio_handler_allocate(s, boost::asio::detail::addressof(h)); 
            ~~~~~~~~~~~~~~~~~~~~~^ 
boost_1_58_0/build/include/boost/asio/detail/handler_alloc_helpers.hpp:48:54: error: no member named 'addressof' in namespace 'boost::asio::detail' 
    asio_handler_deallocate(p, s, boost::asio::detail::addressof(h)); 
... 

我想,这是OS X的具体和有事情做与-std-stdlib标志我通过,因为它编译,如果我同时提供其中的一个,但不是他们两个。我已阅读了很多关于libc++libstdc++的内容,但我需要这些标记作为我的真实代码(可能猜到这只是一个演示代码)需要这些标记才能进行编译,例如,我必须使用libstdC++而不是libC++,而且我需要C++ 11。

有没有关于如何使用最新的boost库而不放弃这些编译器标志的建议?

回答

0

尝试使用-DBOOST_NO_CXX11_ADDRESSOF进行编译。

此外,也许你可以使用-stdlib=libc++ -lstdc++标志(OS X上的程序可以同时使用)编译你的代码(而不是增强)。

0
// Standard library support for addressof. 
#if !defined(BOOST_ASIO_HAS_STD_ADDRESSOF) 
# if !defined(BOOST_ASIO_DISABLE_STD_ADDRESSOF) 
# if defined(__clang__) 
# if defined(BOOST_ASIO_HAS_CLANG_LIBCXX) 
# define BOOST_ASIO_HAS_STD_ADDRESSOF 1 
# elif (__cplusplus >= 201103) 
# define BOOST_ASIO_HAS_STD_ADDRESSOF 1 
# endif // (__cplusplus >= 201103) 
# endif // defined(__clang__) 
... 

它看起来像在升压1.58支票std::addressof最多使用时的libstdC++铿锵和C++ 11是错误的。如果你的libstdC++太旧,那么即使libstdC++没有实现它,boost也会尝试使用std::addressof。看起来您可以定义BOOST_ASIO_DISABLE_STD_ADDRESSOF来解决该问题。

+0

Apple在Mac OS X上发布的libstdC++相当老旧。 (4.2.1,IIRC)。 –