Cross-Compilation: Windows on Mac

DSP, Plug-in and Host development discussion.
KVRist
82 posts since 26 Sep, 2005 from France

Post Thu Nov 25, 2021 8:18 am

mystran wrote:
Thu Nov 25, 2021 7:55 am
Chaotikmind wrote:
Thu Nov 25, 2021 7:35 am
You just need clang/LLVM that is built to target Windows
you don't need a specially build version of clang since it is inherently a cross-compiler

i directly cross-compile from windows to qnx with an out of the box clang here.
You don't need a "special" build, but you do need a build with the targets enabled when LLVM was built. In other words, you can include just about every target in a single build of LLVM, but that doesn't mean that every built of LLVM has to support every target. Your stock QNX compiler was apparently compiled to include Windows support, but the one that ships with XCode is not.
i'm just using the standard clang you can download on their page, nothing fancy.

KVRian
580 posts since 4 Jan, 2007

Post Thu Nov 25, 2021 8:29 am

Quoting what I said, I don't know if that much nit-picking saying the same was really needed.
You don't need clang, but clang-cl. I don't know if you can use the cl frontend for clang on the version provided by xcode.
Wanting to mean that they probably disable it or provide a patched version. I don't know.

If this doesn't say anything about a missing flag or driver you'd probably be fine:

Code: Select all

clang++ --driver=cl

KVRAF
6578 posts since 12 Feb, 2006 from Helsinki, Finland

Post Thu Nov 25, 2021 8:38 am

rafa1981 wrote:
Thu Nov 25, 2021 8:29 am
If this doesn't say anything about a missing flag or driver you'd probably be fine:

Code: Select all

clang++ --driver=cl
clang: error: unsupported option '--driver=cl'

edit: That's what xcode command-line tools say. I don't have the full xcode installed, but I'd imagine it's probably the same.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRian
580 posts since 4 Jan, 2007

Post Thu Nov 25, 2021 8:43 am

My bad, I'm on mobile. Probably --driver-mode=cl?

EDIT: otherwise getting clang-cl or a clang with the cl frontend enabled for Mac is probably something that someone has done before, so Google should know. Unfortunately I don't really know.

KVRAF
6578 posts since 12 Feb, 2006 from Helsinki, Finland

Post Thu Nov 25, 2021 8:48 am

syntonica wrote:
Thu Nov 25, 2021 8:08 am
Apple clang already targets Intel. I'm not sure what else a build of it would need to support Windows, except possibly 32-bit if Apple stripped support out completely. However, I don't think they'll do that any time soon.
There's quite a few things, different binary formats, support for a different runtime, even a different calling convention for 64-bit... plus you still need Windows headers/libraries too.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRist
82 posts since 26 Sep, 2005 from France

Post Thu Nov 25, 2021 9:07 am

i still don't get why the f**k you would want to use clang-cl on a mac to crosscompile to windows ?!!!

User avatar
KVRian

Topic Starter

1128 posts since 25 Sep, 2014 from Specific Northwest

Post Thu Nov 25, 2021 10:30 am

mystran wrote:
Thu Nov 25, 2021 8:48 am
syntonica wrote:
Thu Nov 25, 2021 8:08 am
Apple clang already targets Intel. I'm not sure what else a build of it would need to support Windows, except possibly 32-bit if Apple stripped support out completely. However, I don't think they'll do that any time soon.
There's quite a few things, different binary formats, support for a different runtime, even a different calling convention for 64-bit... plus you still need Windows headers/libraries too.
Darn it! You're right to a point. I thought Xcode allowed you to choose the binary format, but it's strictly mach-o. :?

Unless this can be overridden, I guess it's going to be off to the CLI... :x

It may be time to put on my big boy coder's pants and actually make a makefile to automagically do all the compiling and linking and throw away my Xcode crutches. I stuck with Xcode just because there was so much for me to learn about formats, switches, bundles, etc. I just wanted to focus on coding.

KVRAF
7111 posts since 17 Feb, 2005

Post Thu Nov 25, 2021 12:15 pm

mystran wrote:
Thu Nov 25, 2021 8:48 am
syntonica wrote:
Thu Nov 25, 2021 8:08 am
Apple clang already targets Intel. I'm not sure what else a build of it would need to support Windows, except possibly 32-bit if Apple stripped support out completely. However, I don't think they'll do that any time soon.
There's quite a few things, different binary formats, support for a different runtime, even a different calling convention for 64-bit... plus you still need Windows headers/libraries too.
Thanks for reminding us. The calling convention is also of particular importance. But most importantly, like you said, is the compiler must support the target platform.

KVRAF
6578 posts since 12 Feb, 2006 from Helsinki, Finland

Post Thu Nov 25, 2021 1:00 pm

camsr wrote:
Thu Nov 25, 2021 12:15 pm
mystran wrote:
Thu Nov 25, 2021 8:48 am
syntonica wrote:
Thu Nov 25, 2021 8:08 am
Apple clang already targets Intel. I'm not sure what else a build of it would need to support Windows, except possibly 32-bit if Apple stripped support out completely. However, I don't think they'll do that any time soon.
There's quite a few things, different binary formats, support for a different runtime, even a different calling convention for 64-bit... plus you still need Windows headers/libraries too.
Thanks for reminding us. The calling convention is also of particular importance. But most importantly, like you said, is the compiler must support the target platform.
The calling convention thing is actually kinda silly, 'cos basically every other operating system follows the SysV ABI, but ... on Windows it's basically completely different.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

User avatar
KVRian

Topic Starter

1128 posts since 25 Sep, 2014 from Specific Northwest

Post Thu Nov 25, 2021 1:31 pm

mystran wrote:
Thu Nov 25, 2021 1:00 pm
camsr wrote:
Thu Nov 25, 2021 12:15 pm
mystran wrote:
Thu Nov 25, 2021 8:48 am
syntonica wrote:
Thu Nov 25, 2021 8:08 am
Apple clang already targets Intel. I'm not sure what else a build of it would need to support Windows, except possibly 32-bit if Apple stripped support out completely. However, I don't think they'll do that any time soon.
There's quite a few things, different binary formats, support for a different runtime, even a different calling convention for 64-bit... plus you still need Windows headers/libraries too.
Thanks for reminding us. The calling convention is also of particular importance. But most importantly, like you said, is the compiler must support the target platform.
The calling convention thing is actually kinda silly, 'cos basically every other operating system follows the SysV ABI, but ... on Windows it's basically completely different.
I've never heard it called SysV before.

Linux = elf
MacOS = mach-O (if I understand it correctly, a mutant, Applified version of elf) (I still call it macho, as in overly manly)
Windows = PE (Portable Executable)

With clang, you just use the abi switch to set the format.

KVRAF
6578 posts since 12 Feb, 2006 from Helsinki, Finland

Post Thu Nov 25, 2021 1:46 pm

syntonica wrote:
Thu Nov 25, 2021 1:31 pm
mystran wrote:
Thu Nov 25, 2021 1:00 pm
The calling convention thing is actually kinda silly, 'cos basically every other operating system follows the SysV ABI, but ... on Windows it's basically completely different.
I've never heard it called SysV before.

Linux = elf
MacOS = mach-O (if I understand it correctly, a mutant, Applified version of elf) (I still call it macho, as in overly manly)
Windows = PE (Portable Executable)
Calling convention is a different thing from the binary file format. When a function calls another function, the calling convention specifies how the arguments are passed. The convention used by just about every OS (except Windows) for amd64 is known as the System V ABI, even though "System V" (which is a version of Unix) is not terribly relevant these days.

edit: Also for 32-bit builds, most of the Winapi wants so called "stdcall" calling convention that is different from the "cdecl" calling convention which is "normal" calling convention on 386.

edit2: It might be the case that clang can actually be convinced to emit the different calling conventions even if there's no explicit support for a given platform, but in any case at least the linker should understand PE or it won't be able to link with Windows system libraries.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

User avatar
KVRian

Topic Starter

1128 posts since 25 Sep, 2014 from Specific Northwest

Post Thu Nov 25, 2021 2:17 pm

mystran wrote:
Thu Nov 25, 2021 1:46 pm
syntonica wrote:
Thu Nov 25, 2021 1:31 pm
mystran wrote:
Thu Nov 25, 2021 1:00 pm
The calling convention thing is actually kinda silly, 'cos basically every other operating system follows the SysV ABI, but ... on Windows it's basically completely different.
I've never heard it called SysV before.

Linux = elf
MacOS = mach-O (if I understand it correctly, a mutant, Applified version of elf) (I still call it macho, as in overly manly)
Windows = PE (Portable Executable)
Calling convention is a different thing from the binary file format. When a function calls another function, the calling convention specifies how the arguments are passed. The convention used by just about every OS (except Windows) is known as the System V ABI, even though "System V" (which is a version of Unix) is not terribly relevant these days.
Oh oh oh... Sorry about that, I misunderstood. Windows doesn't use the bog standard? That's all I need. More ammo for my Windows-based aggression. :lol:

However, there's a switch to specify the end product is for Windows. Yes, I had to go check. I'm still learning how all this works. I thought specifying the abi switch would do it. Maybe the target switch will make it redundant.

clang -target x86_64-pc-windows-gnu

Or similar. However, I think this makes the case for ditching Xcode at this point and moving to an editor I like that does code folding properly and using make files.

KVRAF
6578 posts since 12 Feb, 2006 from Helsinki, Finland

Post Thu Nov 25, 2021 2:29 pm

syntonica wrote:
Thu Nov 25, 2021 2:17 pm
clang -target x86_64-pc-windows-gnu
I think there's x86_64-pc-windows-msvc if you're prefer to just use MSVC libraries.. but no idea how to get those on mac.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

User avatar
KVRian

Topic Starter

1128 posts since 25 Sep, 2014 from Specific Northwest

Post Thu Nov 25, 2021 2:49 pm

I have all the gnu stuff including the headers and .a files for linking. I just need to copy them over. Somebody posted previously on how to get the MSVC files.

I was for sure there must be at least one person out there who's doing this, even if it's just on a single server running nightly builds, who could give me some tips and pitfalls to look out for. I have very limited space in my world right now and I'm using three laptops--music production, programming and daily business and then the crappy Windows laptop. I'd love to turn it into a Linux laptop, though, and install Windows on a VM for occasional testing. Currently, it's a waste of decent hardware. The other option is that when I get a new MacBook, turning the music one into a dual boot with Bootcamp and getting rid of the Windows laptop.

Return to “DSP and Plug-in Development”