Cross-compile macOS to Ubuntu

Paolo Invernizzi paolo.invernizzi at
Wed Dec 26 18:06:47 UTC 2018

On Thursday, 20 December 2018 at 21:47:40 UTC, kinke wrote:
> On Thursday, 20 December 2018 at 17:37:23 UTC, Paolo Invernizzi 
> wrote:
>> I've tried linking against the vanilla `` but without 
>> success... so:
>> - someone can point me to correct missing `.so` and `.o` to 
>> link, and their location?
> That mess wrt. distro-specific default libs/object files/other 
> switches being injected by gcc into the linker command line is 
> the reason we recommend using a cross-gcc toolchain for 
> Linux/BSD targets. Anyway, you can invoke `gcc dummy.c -v` in 
> Ubuntu to check the default linker args added by gcc, and work 
> your way from there. E.g., see the first paragraph in 
> In my case on Ubuntu 18.04, the ugly linker cmdline is:
> /usr/lib/gcc/x86_64-linux-gnu/7/collect2 -plugin 
> /usr/lib/gcc/x86_64-linux-gnu/7/ 
> -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper 
> -plugin-opt=-fresolution=/tmp/ccqp6nEf.res 
> -plugin-opt=-pass-through=-lgcc 
> -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc 
> -plugin-opt=-pass-through=-lgcc 
> -plugin-opt=-pass-through=-lgcc_s --sysroot=/ --build-id 
> --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed 
> -dynamic-linker /lib64/ -pie -z now -z 
> relro 
> /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/7 -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/7/../../.. <DUMMY.o> -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o

Thank you kinke,

Coping the relevant files and building with the command line 
below [1] produce an executable, but fails on Linux  [2], oh 

BTW, I read some threads [3], and like Atila I'm not able to use 
lld also on Ubuntu with LDC 1.13...

No problems, I can stick with Docker builds right now, anyway, 
suggestions are welcome!


--- Paolo

[1] ldc2 -mtriple=x86_64-unknown-linux-gnu -link-internally 
-L--eh-frame-hdr -L-m -Lelf_x86_64 -L--hash-style=gnu -L-pie -L-z 
-Lnow -L-z -Lrelro -L./ubuntu/usr/lib/x86_64-linux-gnu/Scrt1.o 
-L-L./ubuntu/ldc-1.13.0/lib -L-L./ubuntu/lib/x86_64-linux-gnu 
-L-dynamic-linker -L/lib64/ -v hello.d

root at 84eb0783a80b:/prj# ./hello
Trace/breakpoint trap
root at 84eb0783a80b:/prj# gdb ./hello
(gdb) r
Starting program: /prj/hello
warning: Error disabling address space randomization: Operation 
not permitted
warning: Could not trace the inferior process.
warning: ptrace: Operation not permitted
During startup program exited with code 127.


More information about the Digitalmars-d mailing list