在 windows 8.1 上使用 clang-cl 64 位
Using clang-cl 64 bit on windows 8.1
我刚开始在 windows 上使用 clang-cl,因为我需要在 64 位应用程序中使用内联汇编,而 Visual Studio 2015 不支持,所以我被告知要使用 clang- cl.
我从 here 下载了预构建的二进制文件 (clang 3.7.0),windows 64 位版本。
所以我尝试制作我的第一个程序,但遗憾的是它没有编译。相同的代码在 Visual Studio 2015 上编译(汇编语句除外)。
请帮助
这是我在 admin cmd 中使用的命令(之前的 I 运行 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.1\include\um\winuser.h(8705,21) : note:
expanded from macro 'MessageBox'
#define MessageBox MessageBoxA
^~~~~~~~~~~
C:\Program Files (x86)\Windows Kits.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 位上进行编译。我该怎么做?
如果要将宽字符串传递给 MessageBox
等函数,则在 #include <windows.h>
之前需要 #define UNICODE
我刚开始在 windows 上使用 clang-cl,因为我需要在 64 位应用程序中使用内联汇编,而 Visual Studio 2015 不支持,所以我被告知要使用 clang- cl.
我从 here 下载了预构建的二进制文件 (clang 3.7.0),windows 64 位版本。
所以我尝试制作我的第一个程序,但遗憾的是它没有编译。相同的代码在 Visual Studio 2015 上编译(汇编语句除外)。
请帮助
这是我在 admin cmd 中使用的命令(之前的 I 运行 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.1\include\um\winuser.h(8705,21) : note:
expanded from macro 'MessageBox'
#define MessageBox MessageBoxA
^~~~~~~~~~~
C:\Program Files (x86)\Windows Kits.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 位上进行编译。我该怎么做?
如果要将宽字符串传递给 MessageBox
#include <windows.h>
之前需要 #define UNICODE