I am trying to cross-compile C applications from Linux (64-bit) to Windows (64 bit) using Clang. I read the page in cross-compilation , which was not very useful.
As a simple test, I have the following code in test.c
:
#include <stdio.h> int main() { puts("hello world"); return 0; }
So far, I guess clang -o test -target x86_64-win64-?ABI? test.c
clang -o test -target x86_64-win64-?ABI? test.c
However, I have no idea what ABI uses Windows 64 bit. When I run clang with the target triple x86_64-win64-abcdefg
, it seems to compile in order, i.e. ends without errors and leads to something that is somewhat valid binary. This makes no sense, given that abcdefg
definitely not a valid ABI. The resulting binary is too large for such a small program, and Windows seems to consider this a 16-bit program (???). The parsing in it shows links to "linux" and "gnu", so it would seem that Clang is not even trying to compile for Windows.
The win32 targeting ( x86_64-win32-???ABI???
) results in the following error message:
test.c:1:10: fatal error: 'stdio.h' file not found
This error, if I am not mistaken, is the result of the fact that she does not know where to look for system files. I assume that Clang stores Windows header files somewhere, as it claims to be able to cross-compile; but where? If this is not the case, then somewhere can I download them?
Is there a list of all architectures, systems and ABI Clang? The list on the cross compilation page is not exhaustive.
The page also suggests using -mcpu=...
, but a warning suggests that it is out of date. Instead, as the warning recommends, I tried -mtune=x86_64
. This does not seem to have any effect. Is this even necessary, given that the architecture is listed in the top three?
I have seen some literature that suggests that I need an experimental LLVM lld
linker. This is true? I am having trouble compiling lld and would like to avoid this if possible.