Windows下的Mingw + clang vs Boost:不同类型的错误

Posted

技术标签:

【中文标题】Windows下的Mingw + clang vs Boost:不同类型的错误【英文标题】:Mingw + clang vs Boost under Windows: different kind of errors 【发布时间】:2016-03-10 15:16:40 【问题描述】:

我准备了一个针对 32 位 Windows 的 llvm-clang 编译器。我使用了 3.7.1 并应用了this patch。我得到了一些几乎可以工作的东西,除了我在提升方面有错误。

如果我使用通常的 boost 1.53 标头编译我的项目(通常与 mingw-gcc 一起使用),我会遇到麻烦,包括 boost/interprocess 组件

In file included from [...]/Boost/include-WINDOWS/boost-1_53\boost/interprocess/sync/interprocess_semaphore.hpp:24:
In file included from [...]/Boost/include-WINDOWS/boost-1_53\boost/interprocess/exceptions.hpp:20:
In file included from [...]/Boost/include-WINDOWS/boost-1_53\boost/interprocess/errors.hpp:37:
[...]/Boost/include-WINDOWS/boost-1_53\boost/interprocess/detail/win32_api.hpp:878:48: error: conflicting types for 'VirtualProtect'

如果我然后尝试recompile boost 与:

bootstrap.bat mingw
b2 toolset=clang --with-thread --with-filesystem --with-signals --with-test --with-system --with-regex --with-program_options --with-serialization variant=release link=shared threading=multi

根据 boost 的不同版本,我会收到很多可以尝试忽略的警告,但也有一些错误:

对于 1.56 和 1.57 就这些:(不多,但我不知道如何摆脱它)

In file included from libs\serialization\src\xml_wiarchive.cpp:35:
.\boost/archive/impl/archive_serializer_map.ipp:41:34: error: redeclaration of 'boost::archive::detail::archive_serializer_map::insert' cannot add 'dllexport' attribute
archive_serializer_map<Archive>::insert(const basic_serializer * bs)
                                 ^
.\boost/archive/detail/archive_serializer_map.hpp:42:17: note: previous declaration is here
    static bool insert(const basic_serializer * bs);
                ^
In file included from libs\serialization\src\xml_wiarchive.cpp:35:
.\boost/archive/impl/archive_serializer_map.ipp:49:34: error: redeclaration of 'boost::archive::detail::archive_serializer_map::erase' cannot add 'dllexport' attribute
archive_serializer_map<Archive>::erase(const basic_serializer * bs)
                                 ^
.\boost/archive/detail/archive_serializer_map.hpp:43:17: note: previous declaration is here
    static void erase(const basic_serializer * bs);
                ^
In file included from libs\serialization\src\xml_wiarchive.cpp:35:
.\boost/archive/impl/archive_serializer_map.ipp:61:34: error: redeclaration of 'boost::archive::detail::archive_serializer_map::find' cannot add 'dllexport' attribute
archive_serializer_map<Archive>::find(
                                 ^
.\boost/archive/detail/archive_serializer_map.hpp:44:37: note: previous declaration is here
    static const basic_serializer * find(
                                    ^

对于 1.59 和 1.60 出现一堆 MMX 相关的错误,据我所知,这不是我在准备 llvm-clang 时可以控制的功能:

clang-linux.compile.c++.without-pth bin.v2\libs\thread\build\clang-linux-3.7.1\debug\threading-multi\win32\thread.obj
In file included from libs\thread\src\win32\thread.cpp:17:
In file included from .\boost/thread/thread_only.hpp:15:
In file included from .\boost/thread/win32/thread_data.hpp:11:
In file included from .\boost/thread/win32/thread_primitives.hpp:18:
In file included from .\boost/detail/interlocked.hpp:154:
In file included from C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\intrin.h:26:
In file included from C:\Programs\MinGW\i686-w64-mingw32\include\Intrin.h:154:
In file included from C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\mm3dnow.h:27:
C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\mmintrin.h:28:2: error: "MMX instruction set not enabled"
#error "MMX instruction set not enabled"
 ^
In file included from libs\thread\src\win32\thread.cpp:17:
In file included from .\boost/thread/thread_only.hpp:15:
In file included from .\boost/thread/win32/thread_data.hpp:11:
In file included from .\boost/thread/win32/thread_primitives.hpp:18:
In file included from .\boost/detail/interlocked.hpp:154:
In file included from C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\intrin.h:26:
In file included from C:\Programs\MinGW\i686-w64-mingw32\include\Intrin.h:154:
C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\mm3dnow.h:42:41: error: use of undeclared identifier '__v8qi'
  return (__m64)__builtin_ia32_pavgusb((__v8qi)__m1, (__v8qi)__m2);
                                        ^
C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\mm3dnow.h:42:55: error: use of undeclared identifier '__v8qi'
  return (__m64)__builtin_ia32_pavgusb((__v8qi)__m1, (__v8qi)__m2);
                                                      ^
C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\mm3dnow.h:47:38: error: cannot convert '__m64' to '__v2sf' (vector of 2 'float' values) without a conversion operator
  return (__m64)__builtin_ia32_pf2id((__v2sf)__m);
                                     ^~~~~~~~~~~
C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\mm3dnow.h:52:38: error: cannot convert '__m64' to '__v2sf' (vector of 2 'float' values) without a conversion operator
  return (__m64)__builtin_ia32_pfacc((__v2sf)__m1, (__v2sf)__m2);
                                     ^~~~~~~~~~~~
C:\Programs\LLVM\bin\..\lib\clang\3.7.1\include\mm3dnow.h:52:52: error: cannot convert '__m64' to '__v2sf' (vector of 2 'float' values) without a conversion operator
  return (__m64)__builtin_ia32_pfacc((__v2sf)__m1, (__v2sf)__m2);
                                                   ^~~~~~~~~~~~

有没有办法让任何版本的 boost 在 Windows 下在 MinGW 设置中与 clang 32bit 一起使用?

我也尝试过 llvm 3.8.0,但我无法准备它,因为我的 MinGW 工具链不支持 C++11 的某些部分(以及我尝试过的其他版本,请参阅 here)。

【问题讨论】:

第二个问题,可能与this patch有关 【参考方案1】:

关于 boost.thread: 添加 -msse(或其他)(解决 MMX 指令集未启用错误)后,只需将 -DBOOST_USE_WINDOWS_H 添加到 cxxflags 即可解决 Windows 标头和 boost.date_time 处许多系统函数的不同声明。

例如: cxxflags="-msse -DBOOST_USE_WINDOWS_H"

【讨论】:

以上是关于Windows下的Mingw + clang vs Boost:不同类型的错误的主要内容,如果未能解决你的问题,请参考以下文章

[CMake + MinGW + Windows 10上的Clang

mingw-w64和Linux下的GCC有区别吗

“Qt Creator 2.4.1 for Windows (53 MB)”是不是包含 mingw 或 clang? [关闭]

Mac平台下的Qt程序在Windows下执行编译运行出现的中文乱码问题

在Windows使用clang编译器

让 Clang 在 Windows 上工作