【问题标题】:How to use boost asio with clang/c2如何在 clang/c2 中使用 boost asio
【发布时间】:2016-11-15 01:50:11
【问题描述】:

TL;DR

  • 是否有人能够将 boost asio(boost 版本为 1.61)与 clang/c2(集成到 VS2015 Update 3 中的 clang++ 前端)一起使用?
  • 如果是,您使用了哪些选项?

我有一个使用 boost 的 asio 库的程序。在 Win10 上使用 MSVC++(VS2015 更新 3)和 Ubuntu 14.04 上的 g++4.8 编译时,它可以完美运行,但我也想使用较新版本的 Visual Studio 附带的 clang 前端(我相信自更新 1 以来) .

我的初始命令行选项(从项目属性页面复制)如下所示:

-fpic "stdafx.h" -std=c++1y -fstack-protector "Clang\" -fno-strict-aliasing -ffunction-sections -g2 -gdwarf-2 -O0 -x c++-header -D "_WINSOCK_DEPRECATED_NO_WARNINGS" -D "NOMINMAX" -frtti -fomit-frame-pointer -fdata-sections -fno-ms-compatibility -std=c11 -fexceptions -o "Clang\%(filename).obj" -fms-extensions -fno -短枚举

这给了我以下错误:

void __cdecl boost::detail::atomic_increment(struct __clang::_Atomic<int> *)': Unexpected atomic instruction -- use Windows interlock intrinsics

显然,使用 clang/c2 版本不支持的 clang/gcc 内在函数,而不是使用它在使用 VC++ 编译时使用的特定于 Windows 的内在函数,显然会让人厌烦。我尝试了不同的编译器选项,唯一似乎有任何效果的是取消定义 __clang__ 预处理器符号(在命令行中添加以下选项):

-U "__clang__"

这消除了原子错误,但现在我收到多页错误消息,这些消息似乎与某些 boost mpl 宏有关。以下是前几行:

1>  In file included from main.cpp:1:
1>  In file included from D:\mylibs\boost\include\boost/program_options.hpp:15:
1>  In file included from D:\mylibs\boost\include\boost/program_options/options_description.hpp:13:
1>  In file included from D:\mylibs\boost\include\boost/program_options/value_semantic.hpp:12:
1>  In file included from D:\mylibs\boost\include\boost/any.hpp:20:
1>  In file included from D:\mylibs\boost\include\boost/type_index.hpp:29:
1>  In file included from D:\mylibs\boost\include\boost/type_index/stl_type_index.hpp:40:
1>D:\mylibs\boost\include\boost/mpl/if.hpp(131,23): error : too many arguments provided to function-like macro invocation
1>  BOOST_MPL_AUX_NA_SPEC(3, if_)
1>                        ^
1>  D:\mylibs\boost\include\boost/preprocessor/facilities/expand.hpp(26,10) :  note: macro 'BOOST_PP_EXPAND_I' defined here
1>  # define BOOST_PP_EXPAND_I(x) x
1>           ^

有人对此有解决方案吗?

请注意,我的问题不是关于构建 boost 库本身,如本文所述:Command parameters for b2 in order to build Boost libraries with Microsoft's Clang/C2。是的,我知道 boost 没有对 clang/c2 的官方支持,但我想知道是否有人知道会产生正​​确的 boost 配置宏集的 hack。

【问题讨论】:

    标签: c++ visual-studio boost build clang


    【解决方案1】:

    获取 Boost 标头以使用 Clang/C2 进行干净编译对于使 Clang/C2 有用的关键,因此我们正在努力提供支持对于Clang-style 原子内在函数。它们将在 Clang/C2 的未来更新中提供。

    我不知道有什么方法可以说服 Boost 使用 MSVC 版本的内在函数,同时仍然使用 Clang 进行编译,除非你愿意破解 Boost 标头。

    【讨论】:

    • 感谢您的提醒。出于测试目的,如果有人能确切地告诉我我必须在哪里更改什么,我实际上愿意破解标题。现在,如果我不知道是否有可能,我自己去挖掘 boost 配置头寻找正确的定义,这还不够重要。
    【解决方案2】:

    尝试在编译器选项中定义宏 BOOST_SP_USE_STD_ATOMIC 或紧接在 #include 任何 Boost 标头之前。

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 2015-08-08
      • 1970-01-01
      • 2017-09-02
      • 2016-11-04
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多