如何使用带有 clang/c2 的 boost asio



TL;DR

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

我有一个使用boost的asio库的程序。当在Win10上使用MSVC++(VS2015 Update 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-short-enums

这给了我以下错误:

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__"

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

1>  In file included from main.cpp:1:
1>  In file included from D:mylibsboostincludeboost/program_options.hpp:15:
1>  In file included from D:mylibsboostincludeboost/program_options/options_description.hpp:13:
1>  In file included from D:mylibsboostincludeboost/program_options/value_semantic.hpp:12:
1>  In file included from D:mylibsboostincludeboost/any.hpp:20:
1>  In file included from D:mylibsboostincludeboost/type_index.hpp:29:
1>  In file included from D:mylibsboostincludeboost/type_index/stl_type_index.hpp:40:
1>D:mylibsboostincludeboost/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:mylibsboostincludeboost/preprocessor/facilities/expand.hpp(26,10) :  note: macro 'BOOST_PP_EXPAND_I' defined here
1>  # define BOOST_PP_EXPAND_I(x) x
1>           ^

有人对此有解决方案吗?

请注意,我的问题不是像这篇文章中那样构建 boost 库本身:b2 的命令参数,以便使用 Microsoft 的 Clang/C2 构建 Boost 库。是的,我知道 boost 没有官方支持 clang/c2,但我想知道是否有人知道一个可以产生正确 boost 配置宏集的黑客。

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

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

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

最新更新