I'v just started using clang-cl on windows, because I need to use inline assembly in 64 bit app, and Visual Studio 2015 doesn't support that, so I was told to go for clang-cl.
I downloaded a pre-built binary (clang 3.7.0) from here, the windows 64 bit version.
So I tried to make my first program, but sadly it doesn't compile. The same code does compile on Visual Studio 2015 (except the assembly statement).
Please help
This is the command I used from admin cmd (the I ran on it vsvart32
just before that):
clang-cl.exe -m64 C:\test\Source.cpp
Here is my code:
#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;
}
And this is the clang-cl.exe
output:
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.
EDIT thanks to @Martin Bonner , the problem was I needed to use #define UNICODE
. But now I also need to compile on 64bit. How do I do that?
You need #define UNICODE
before #include <windows.h>
if you are going to pass wide strings to functions like MessageBox