我刚刚开始在windows上使用clang,因为我需要在64位应用程序中使用内联程序集,而Visual 2015不支持这一点,所以我被告知要使用clang。
我从这里下载了一个预建的二进制文件(clang3.7.0),windows 64位版本。
所以我试着做我的第一个程序,但遗憾的是它没有编译。相同的代码在Visual 2015上编译(程序集语句除外)。
请帮帮忙
这是我从admin中使用的命令(在此之前运行的是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,问题是我需要使用#define UNICODE。但是现在我也需要在64位上编译。我该怎么做?
发布于 2015-12-29 17:49:40
如果要将宽字符串传递给像#define UNICODE这样的函数,则需要在#include <windows.h>之前使用MessageBox
https://stackoverflow.com/questions/34516167
复制相似问题