【问题标题】:Using clang-cl 64 bit on windows 8.1在 Windows 8.1 上使用 clang-cl 64 位
【发布时间】:2015-12-29 17:44:05
【问题描述】:


我刚开始在 windows 上使用 clang-cl,因为我需要在 64 位应用程序中使用内联汇编,而 Visual Studio 2015 不支持,所以我被告知要使用 clang-cl。

我从here 下载了一个预构建的二进制文件(clang 3.7.0),Windows 64 位版本。

所以我尝试制作我的第一个程序,但遗憾的是它没有编译。相同的代码可以在 Visual Studio 2015 上编译(汇编语句除外)。

请帮忙

这是我从 admin cmd 使用的命令(在那之前我在上面运行过 vsvart32):
clang-cl.exe -m64 C:\test\Source.cpp

这是我的代码:

#include <Windows.h>
#include <iostream>

int main() {

    int a = 0;
    if(0)//this if-else is to mess up disassmblers
        __asm __emit 0xE8 //only this line doesn't go on VS2015
    else
    a=3;

    if (IsDebuggerPresent())
    MessageBox(
        NULL,
        (LPCWSTR)L"Debugger detected!!",
        (LPCWSTR)L"!!!!!",
        MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
        );
    return 0;
}

这是clang-cl.exe 输出:

C:\Program Files\LLVM\bin>clang-cl.exe -m64 C:\test\Source.cpp
C:\test\Source.cpp(13,2) :  error: no matching function for call to
  'MessageBoxA'
    MessageBox(
    ^~~~~~~~~~
C:\Program Files (x86)\Windows Kits\8.1\include\um\winuser.h(8705,21) :       note:
  expanded from macro 'MessageBox'
#define MessageBox  MessageBoxA
                ^~~~~~~~~~~
C:\Program Files (x86)\Windows Kits\8.1\include\um\winuser.h(8689,1) :  note:
  candidate function not viable: no known conversion from 'LPCWSTR'
  (aka 'const wchar_t *') to 'LPCSTR' (aka 'const char *') for 2nd argument
MessageBoxA(
^
1 error generated.

编辑感谢@Martin Bonner,问题是我需要使用#define UNICODE。但现在我还需要在 64 位上编译。我该怎么做?

【问题讨论】:

    标签: c++ 64-bit clang inline-assembly clang-cl


    【解决方案1】:

    如果您要将宽字符串传递给像MessageBox 这样的函数,则在#include &lt;windows.h&gt; 之前需要#define UNICODE

    【讨论】:

    • 太棒了!但现在我得到这个错误:libcmt.lib(typinfo.obj) : fatal error LNK1112: module machine type 'X86' conflic ts with target machine type 'x64' clang-cl.exe: error: linker command failed with exit code 1112 (use -v to see in vocation)
    • 您需要将链接器指向 64 位库 - 但这需要是一个单独的问题(我不知道答案。抱歉。)
    • 不要尝试扩展这个问题。这个问题已经回答了。再问一个问题
    猜你喜欢
    • 2016-04-04
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    相关资源
    最近更新 更多