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

Majestio via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Fri Jul 17 00:36:50 PDT 2015


Hi, Kai!

I rebuilt the whole system of cross-compile again, and recorded 
all of his actions step by step. I note, in my opinion, the main 
points.

First part: make from .c source
========================================================
#!/bin/sh

export TARGET="i686-w64-mingw32.static"
export MXE="/home/majestio/Dev/cross/mxe/usr"
export PATH="$MXE/bin:$PATH"

# Step 1
$MXE/bin/$TARGET-gcc -c hello.c

# Step 2
$MXE/bin/$TARGET-gcc hello.o -o hello.exe
------------------------------------------------------------------------------
Result: ok
hello.exe was successfully launched on the Windows host

then ...

Secont part: make from .d source
------------------------------------------------------------------------------
#!/bin/sh

export TARGET="i686-w64-mingw32.static"
export MXE="/home/majestio/Dev/cross/mxe/usr"
export LLVM="/home/majestio/Dev/cross/llvm"
export DLANG="/home/majestio/Dev/cross/dlang/$TARGET"
export PATH="$MXE/bin:$LLVM/bin:$DLANG/bin:$PATH"

# Step 1
$TARGET-ldc2 -c -gcc=$TARGET-gcc -mtriple=$TARGET hello.d

# Step 2
$TARGET-gcc hello.obj \
-L$LLVM/lib \
-L$DLANG/lib \
-lphobos2-ldc \
-lcurl \
-ldruntime-ldc \
-v \
-o hello.exe

# Step debug
echo "Find libraries ..."
find $DLANG -type f | xargs grep -l "D14TypeInfo_Const6"
echo "For comparison with the specified path ..."
echo "$DLANG/lib"
------------------------------------------------------------------------------
Result: only produced .obj file

Output:
------------------------------------------------------------------------------
majestio at funtoo ~/Dev/projects/hello-d $ ./hello_d-1.sh
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32.static-gcc
COLLECT_LTO_WRAPPER=/home/majestio/Dev/cross/mxe/usr/libexec/gcc/i686-w64-mingw32.static/5.1.0/lto-wrapper
Target: i686-w64-mingw32.static
Configured with: 
/home/majestio/Dev/cross/mxe/tmp-gcc-i686-w64-mingw32.static/gcc-5.1.0/configure --target=i686-w64-mingw32.static --build=x86_64-pc-linux-gnu --prefix=/home/majestio/Dev/cross/mxe/usr --libdir=/home/majestio/Dev/cross/mxe/usr/lib --enable-shared=libstdc++ --enable-languages=c,c++,objc,fortran --enable-version-specific-runtime-libs --with-gcc --with-gnu-ld --with-gnu-as --disable-nls --disable-shared --disable-multilib --without-x --disable-win32-registry --enable-threads=posix --disable-libgomp --with-gmp=/home/majestio/Dev/cross/mxe/usr --with-isl=/home/majestio/Dev/cross/mxe/usr --with-mpc=/home/majestio/Dev/cross/mxe/usr --with-mpfr=/home/majestio/Dev/cross/mxe/usr --with-as=/home/majestio/Dev/cross/mxe/usr/bin/i686-w64-mingw32.static-as --with-ld=/home/majestio/Dev/cross/mxe/usr/bin/i686-w64-mingw32.static-ld --with-nm=/home/majestio/Dev/cross/mxe/usr/bin/i686-w64-mingw32.static-nm
Thread model: posix
gcc version 5.1.0 (GCC)
COMPILER_PATH=/home/majestio/Dev/cross/mxe/usr/libexec/gcc/i686-w64-mingw32.static/5.1.0/:/home/majestio/Dev/cross/mxe/usr/libexec/gcc/i686-w64-mingw32.static/5.1.0/:/home/majestio/Dev/cross/mxe/usr/libexec/gcc/i686-w64-mingw32.static/:/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/:/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/:/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/../../../../i686-w64-mingw32.static/bin/
LIBRARY_PATH=/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/:/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/../../../../i686-w64-mingw32.static/lib/../lib/:/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/../../../../i686-w64-mingw32.static/lib/
COLLECT_GCC_OPTIONS='-L/home/majestio/Dev/cross/llvm/lib' 
'-L/home/majestio/Dev/cross/dlang/i686-w64-mingw32.static/lib' 
'-v' '-o' 'hello.exe' '-mtune=generic' '-march=pentiumpro'
  
/home/majestio/Dev/cross/mxe/usr/libexec/gcc/i686-w64-mingw32.static/5.1.0/collect2 -plugin /home/majestio/Dev/cross/mxe/usr/libexec/gcc/i686-w64-mingw32.static/5.1.0/liblto_plugin.so -plugin-opt=/home/majestio/Dev/cross/mxe/usr/libexec/gcc/i686-w64-mingw32.static/5.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccbzqvbz.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pe -Bdynamic -o hello.exe /home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/../../../../i686-w64-mingw32.static/lib/../lib/crt2.o /home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/crtbegin.o -L/home/majestio/Dev/cross/llvm/lib -L/home/majestio/Dev/cross/dlang/i686-w64-mingw32.static/lib -L/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0 -L/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/../../../../i686-w64-mingw32.static/lib/../lib -L/home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/../../../../i686-w64-mingw32.static/lib hello.obj -lphobos2-ldc -lcurl -ldruntime-ldc -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt /home/majestio/Dev/cross/mxe/usr/lib/gcc/i686-w64-mingw32.static/5.1.0/crtend.o
hello.obj:(.text[__D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv]+0x1a): undefined reference to `_D3std5stdio6stdoutS3std5stdio4File'
hello.obj:(.text[__D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv]+0x6c): undefined reference to `_D3std9exception14__T7enforceTbZ7enforceFNaNfbLAxaAyakZb'
hello.obj:(.text[__D5hello16__moduleinfoCtorZ]+0x8): undefined 
reference to `_Dmodule_ref'
hello.obj:(.text[__D5hello16__moduleinfoCtorZ]+0x13): undefined 
reference to `_Dmodule_ref'
hello.obj:(.text[_main]+0x2f): undefined reference to 
`_d_run_main'
hello.obj:(.rdata[__D12TypeInfo_xAk6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D12TypeInfo_Axk6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Array6__vtblZ'
hello.obj:(.rdata[__D11TypeInfo_xk6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D11TypeInfo_xk6__initZ]+0x8): undefined 
reference to `_D10TypeInfo_k6__initZ'
hello.obj:(.rdata[__D11TypeInfo_ya6__initZ]+0x0): undefined 
reference to `_D18TypeInfo_Invariant6__vtblZ'
hello.obj:(.rdata[__D11TypeInfo_ya6__initZ]+0x8): undefined 
reference to `_D10TypeInfo_a6__initZ'
hello.obj:(.rdata[__D12TypeInfo_xAa6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D12TypeInfo_xAa6__initZ]+0x8): undefined 
reference to `_D12TypeInfo_Axa6__initZ'
hello.obj:(.rdata[__D11TypeInfo_xb6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D11TypeInfo_xb6__initZ]+0x8): undefined 
reference to `_D10TypeInfo_b6__initZ'
hello.obj:(.rdata[__D11TypeInfo_xi6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D11TypeInfo_xi6__initZ]+0x8): undefined 
reference to `_D10TypeInfo_i6__initZ'
hello.obj:(.rdata[__D11TypeInfo_xa6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D11TypeInfo_xa6__initZ]+0x8): undefined 
reference to `_D10TypeInfo_a6__initZ'
hello.obj:(.rdata[__D11TypeInfo_xh6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D11TypeInfo_xh6__initZ]+0x8): undefined 
reference to `_D10TypeInfo_h6__initZ'
hello.obj:(.rdata[__D13TypeInfo_xAya6__initZ]+0x0): undefined 
reference to `_D14TypeInfo_Const6__vtblZ'
hello.obj:(.rdata[__D13TypeInfo_xAya6__initZ]+0x8): undefined 
reference to `_D12TypeInfo_Aya6__initZ'
hello.obj:(.data[__D5hello12__ModuleInfoZ]+0xc): undefined 
reference to `_D3std5stdio12__ModuleInfoZ'
collect2: error: ld returned 1 exit status
Find libraries ...
/home/majestio/Dev/cross/dlang/i686-w64-mingw32.static/lib/libphobos2-ldc-debug.a
/home/majestio/Dev/cross/dlang/i686-w64-mingw32.static/lib/libdruntime-ldc.a
/home/majestio/Dev/cross/dlang/i686-w64-mingw32.static/lib/libphobos2-ldc.a
/home/majestio/Dev/cross/dlang/i686-w64-mingw32.static/lib/libdruntime-ldc-debug.a
For comparison with the specified path ...
/home/majestio/Dev/cross/dlang/i686-w64-mingw32.static/lib
------------------------------------------------------------------------------

On Tuesday, 14 July 2015 at 16:38:52 UTC, Kai Nacke wrote:
> BTW: Can you cross-compile a C hello world without problems?
Yes.

> Did you compile druntime and phobos for the mingw target? If 
> yes where did you place the libraries?
Yes. When I built the library, I inserted for your advice in 
ruttime/CMakeLists.txt:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER i686-w64-mingw32.static-gcc)
set(CMAKE_CXX_COMPILER i686-w64-mingw32.static-g++)

> The other missing symbols are from druntime and phobos. This 
> indicates that these libraries are not found. Did you also 
> cross-compile the curl library?

Curl is present.

> You can use the -v command line option with ldc2 to see the 
> call to gcc. This is useful for debugging.

I used it.

... In general, do not grow coconuts :((

Regards,
Majestio


More information about the digitalmars-d-ldc mailing list