How to build a set of toolchains for cross-compiling for LDC?

Jacob Carlborg via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Tue May 17 02:11:32 PDT 2016


On 2015-06-28 16:03, Majestio wrote:
> Hi all!
>
> I apologize in advance for my English, I use Google Translator :-\
>
> I became interested in the D programming language recently. I want build
> a comfortable environment for cross-compilation. In my Linux Funtoo
> already has a similar environment for C/C++ based http://mxe.cc:
>
> i686-w64-mingw32.shared
> i686-w64-mingw32.static
> x86_64-w64-mingw32.shared
> x86_64-w64-mingw32.static
>
> ... and more libs, including Qt 5.4.2 for each toolchain.
>
> So far I have built native LDC, and native "Hello world" is compiled and
> linked successfully.
>
> Actually, the question is how to build step by step for the environment
> LDC for  cross-compile, similar MXE?
>
> Just in case, my directory structure:
>
> /home/majestio/dev/cross/mxe - C/C++ cross-compile env
> /home/majestio/dev/cross/llvm - LLVM,Clang,LDC

I've successfully cross-compiled using LDC and ELLCC.

These are the steps I took to cross-compile from OS X to Linux

1. Download the ELLCC compile [1], pick the platform for which you'll be 
running the compiler

2. Download LDC for both OS X and Linux 64bit [2]

3. Symlink ellcc/bin/ecc to ellcc/bin/ecc-x86_64-linux. Do the same for 
ecc++

4. Copy all files in ldc2-0.17.1-linux-x86_64/lib to 
dc2-0.17.1-osx-x86_64/lib and add a "x86_64-linux" prefix to the name of 
the library files

5. Copy ldc2-0.17.1-osx-x86_64/etc/ldc2.conf to 
ldc2-0.17.1-osx-x86_64/etc/ldc2-x86_64-linux.conf

6. Modify ldc2-0.17.1-osx-x86_64/etc/ldc2-x86_64-linux.conf to use the 
library files with the "x86_64-linux" prefix

7. Create a new C (backtrace.c) file with the following content:

#include <stdlib.h>

int backtrace(void **buffer, int size) { return 0; }
char **backtrace_symbols(void *const *buffer, int size) { return NULL; }
void backtrace_symbols_fd(void *const *buffer, int size, int fd) {}

Compile with "ellcc/bin/ecc-x86_64-linux backtrace.c -c -o backtrace.o"

8. Compile a D program with:

CC=ellcc/bin/x86_64-linux-ecc++ ldc2-0.17.1-osx-x86_64/bin/ldc2 
-mtriple=x86_64-uknown-linux 
-conf=ldc2-0.17.1-osx-x86_64/etc/ldc2-x86_64-linux.conf backtrace.o main.d

The only issues is that musl, the C standard library used by ELLCC is 
missing three symbols. I created a file backtrace.c with stubs for these 
symbols.

[1] http://ellcc.org/releases/
[2] https://github.com/ldc-developers/ldc/releases/tag/v0.17.1

-- 
/Jacob Carlborg


More information about the digitalmars-d-ldc mailing list