Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I recently learned that Clang supports this kind of cross-compiling out of the box. https://mcilloni.ovh/2021/02/09/cxx-cross-clang/

The main difference is that Clang does not ship with headers/libraries for different platforms, as Zig appears to do. You need to give Clang a "sysroot" -- a path that has the headers/libraries for the platform you want to compile for.

If you create a bunch of sysroots for various architectures, you can do some pretty "easy" cross-compiling with just a single compiler binary. Docker can be a nice way of packaging up these sysroots (especially combined with Docker images like manylinux: https://github.com/pypa/manylinux). Gone are the days when you had to build a separate GCC cross-compiler for each platform you want to target.



Yes, for instance for ossia score, the sequencer I'm working on which does some runtime compiling of c++ through clang & llvmjit, I ship a sdk for each platform with all the libc, libc++ headers. What a pain it was !

My scripts are the create-sdk-... Here if that can be useful to anyone: https://github.com/ossia/score/tree/master/ci and the SDKs are available at https://github.com/ossia/sdk




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

Search: