【发布时间】: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