Cross-compile with LDC
Joakim via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Fri Feb 19 00:51:18 PST 2016
On Thursday, 18 February 2016 at 21:11:52 UTC, Jacob Carlborg
wrote:
> If I want to cross-compile with LDC, the host being OS X and
> the target being Linux 64bit. What would be the easiest way,
> can I use the tools from ELLCC [1]?
>
> Can I specify the linker in LDC or do I need to separately link?
>
> [1] http://ellcc.org
As in linux/AArch64? There are two steps to cross-compiling with
ldc:
1. Cross-compile druntime and phobos for the OS/arch combo you
want. This is easy to do using the cmake build scripts that come
with the ldc source, assuming ldc, druntime and phobos already
support the platform you want. Simply set D_FLAGS to the llvm
triple and any other specific flags you need, as I do for
Android/ARM
(https://gist.github.com/joakim-noah/63693ead3aa62216e1d9#file-ldc_android_arm-L3131), and set CC to a C cross-compiler for your target platform (export CC=/home/jacob/elcc-linux-aarch64/bin/clang), as there are a few C files and one asm file that druntime and phobos require. You may also need to set RT_CFLAGS, depending on the C compiler for your platform (can be seen in the link below).
2. Specify a linker for your OS/arch when cross-compiling with
ldc. If you have a C compiler already configured to use that
linker, as elcc might provide, all that requires is setting CC to
that C compiler before running ldc, as shown above. Otherwise,
you can cross-compile to object files using ldc and the -c flag,
then run your linker by hand, as I do with the Android NDK
(https://gist.github.com/joakim-noah/63693ead3aa62216e1d9#file-ldc_android_arm-L3164).
More information about the digitalmars-d-ldc
mailing list