Hacker News new | past | comments | ask | show | jobs | submit login

Zig and Nim both have excellent cross compiling support out of the box.

Zig extends that excellent support to its embedded LLVM C compiler - it’s probably the easiest way to cross compile C across operating system boundaries these days.




https://nim-lang.org/docs/nimc.html#cross-compilation

Nim doesn't seem to have excellent cross compiling support out of the box. It simply relies on cross platform toolchains that you have to set up.

Good luck setting up cross platform GCC.

Zig uses musl AFAIK? That can often be problematic.


Zig supports musl, glibc, macOS libc, and mingw I think:

https://ziglang.org/download/0.7.0/release-notes.html

But yeah, I think musl is the main target, and it ships with the source for it


But it only uses musl for cross compilation, no?

I don't think it uses glibc to compile Linux binaries on macOS or macOS libc to compile macOS binaries on Linux.


It can target glibc in a cross-compile setting.

https://andrewkelley.me/post/zig-cc-powerful-drop-in-replace...


musl is a Linux libc, so you can't use in on any other OS (because it wouldn't know how to send syscalls to the kernel).

macOS handles libc a little differently from Linux; whereas the Linux kernel publishes its syscall API, and allows programs to make syscalls however they want (e.g. with glibc or musl, or with go, which does syscalls itself), macOS's syscall API is subject to change at any time, and the only (supported) way to make syscalls is to dynamically link to the system libc.


Nim always relies on an underlying platform compiler.

Getting an .o out from a cross compiler is easy, in my experience - the big problem is getting libraries, includes and linkage right. And in my (admittedly small) experience, Nim makes that part much simpler as soon as you have a compiler set up (which in my case was an apt-get away)


Yeah it's nice when it's an apt install away.

Not so nice on Windows or macOS.

While Go supports it all out of the box.


But do note the apt-get doesn’t get you far. You now have a compiler that can produce .o, but headers, libraries, borked make files that are unaware of cross compiles etc are still a problem.

Not so with Nim.


FreePascal works well, too, once it is installed

To compile to linux it needs to have a linker installed. For windows it has an internal linker, so probably does not even need that




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: