【问题标题】:How to compile Windows API C++ code with clang 11? [duplicate]如何使用 clang 11 编译 Windows API C++ 代码? [复制]
【发布时间】:2020-12-29 22:31:29
【问题描述】:

我刚刚从 llvm 官方网站下载了 llvm-11-win64(我需要使用 clang 而不是 mingw-g++)。我正在尝试编译一个包含 的测试 C++ 文件(头文件取自 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/include\windows.h:69:
In file included from C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include\windef.h:8:
In file included from C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include\minwindef.h:163:
In file included from C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include\winnt.h:1554:
In file included from C:\Program Files\LLVM\lib\clang\11.0.0\include\x86intrin.h:15:
In file included from C:\Program Files\LLVM\lib\clang\11.0.0\include\immintrin.h:15:
C:\Program Files\LLVM\lib\clang\11.0.0\include\mmintrin.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);
                                       ^~~~~~~~~~~

【问题讨论】:

    标签: c++ winapi clang


    【解决方案1】:

    头文件取自 mingw64 安装

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 2014-05-12
    • 2012-11-16
    • 1970-01-01
    • 2012-10-18
    • 2012-04-01
    • 2012-12-16
    相关资源
    最近更新 更多