c++ - 如何在 clang/c2 中使用 boost asio

标签 c++ visual-studio boost build clang

长话短说:

  • 有没有人能够将 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-short-enums

这给了我以下错误:

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

所以显然 boost 厌倦了使用 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。

最佳答案

Boost header 与 Clang/C2 一起干净地编译对于使 Clang/C2 有用至关重要,因此我们正在努力提供支持对于 Clang 风格 原子内在函数。它们将在 Clang/C2 的 future 更新中提供。

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

关于c++ - 如何在 clang/c2 中使用 boost asio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38335334/

相关文章:

c++ - 静态、共享和可执行 - Windows 和 Linux

c++ - boost::dynamic_bitset 的逆序

c++ - VC++ 2010 中的 C++ Boost 安装问题(找不到文件)

c++ - 访问静态成员时出现 EXC_BAD_ACCESS?

c++ - 有没有一种标准的方法来为 boost::test 的输出着色

c# - web.config 转换从 web.template.xml 不工作

c++ - 错误 "fatal error C1034: windows.h: no include path set"

c++ - 为什么从 DLL 调用时 boost::wave::context 构造函数会死锁?

c++ - 哪些文件属于 CDT 托管构建中的构建目标?

asp.net - 如何在 Visual Studio 2008 调试器中查看 session 变量?