如何用clang 11编译Windows API C++代码



我刚刚从llvm官方网站下载了llvm-11-win64(我需要使用clang而不是mingw-g++(。我正在尝试编译一个测试C++文件,该文件包括<windows.h>(头文件取自mingw64安装(

// test.cpp
#include <windows.h>
bool WINAPI DllMain(HINSTANCE hModule, DWORD fwdReason, LPVOID reserved)
{
return TRUE;
}

典型的命令行编译会出现错误,我应该做一些不同的操作吗?

$ clang++ -I "/c/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include/" -c test.cpp
In file included from test.cpp:2:
In file included from C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/includewindows.h:69:
In file included from C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/includewindef.h:8:
In file included from C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/includeminwindef.h:163:
In file included from C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/includewinnt.h:1554:
In file included from C:Program FilesLLVMlibclang11.0.0includex86intrin.h:15:
In file included from C:Program FilesLLVMlibclang11.0.0includeimmintrin.h:15:
C:Program FilesLLVMlibclang11.0.0includemmintrin.h:67:40: error: cannot initialize a parameter of type '__attribute__((__vector_size__(2 * sizeof(int)))) int'
(vector of 2 'int' values) with an rvalue of type '__v2si' (aka 'int')
return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
^~~~~~~~~~~

头文件取自mingw64安装

Microsoft提供了可与Clang一起使用的官方Windows标头(如果我没有记错的话,Microsoft不久前就开始在Visual Studio中提供Clang(。

最新更新