[英]OS X clang C++11 and libstdc++ boost compilation problems
我已经编译了两个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库而不放弃这些编译器标志的任何建议?
尝试使用-DBOOST_NO_CXX11_ADDRESSOF
进行编译。
另外,也许您可以使用-stdlib=libc++ -lstdc++
标志(而不是OS X上的程序同时使用两者)来编译代码(而不是boost)。
// 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
来解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.