【问题标题】:OS X clang C++11 and libstdc++ boost compilation problemsOS X clang C++11 和 libstdc++ boost 编译问题
【发布时间】:2016-01-05 03:22:28
【问题描述】:

我已经编译了两个 Boost 库版本 - 1.54 和 1.58 类似:

$ 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;
}

像这样: $ g++ -c -std=gnu++11 -stdlib=libstdc++ -I main.cpp

它为 Boost 1.54.0 编译完美,并为 Boost 1.58.0 提供错误(超过 20 个):

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 库有什么建议吗?

【问题讨论】:

    标签: c++ c++11 boost libstdc++ libc++


    【解决方案1】:

    尝试用-DBOOST_NO_CXX11_ADDRESSOF编译。

    也许你也可以使用-stdlib=libc++ -lstdc++ 标志编译你的代码(不是boost)(OS X 上的程序可以同时使用两者)。

    【讨论】:

      【解决方案2】:
      // 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__)
      ...
      

      在将 clang 与 libstdc++ 和 c++11 一起使用时,在 boost 1.58 及更高版本中检查 std::addressof 似乎是错误的。如果您的 libstdc++ 太旧,那么即使 libstdc++ 没有实现它,boost 也会尝试使用std::addressof。看来您可以定义 BOOST_ASIO_DISABLE_STD_ADDRESSOF 来解决该问题。

      【讨论】:

      • Apple 在 Mac OS X 上提供的 libstdc++ 已经很老了。 (4.2.1,IIRC)。
      猜你喜欢
      • 2012-03-16
      • 2013-05-15
      • 1970-01-01
      • 2012-11-04
      • 2013-08-10
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多