Cross-compile macOS to Ubuntu
Paolo Invernizzi
paolo.invernizzi at gmail.com
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 `libc.so` 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
> https://github.com/ldc-developers/ldc/pull/2203#issuecomment-339167131. 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/liblto_plugin.so
> -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/ld-linux-x86-64.so.2 -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
well...
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!
Cheers,
--- 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./ubuntu/usr/lib/x86_64-linux-gnu/crti.o
-L./ubuntu/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
-L-L./ubuntu/ldc-1.13.0/lib -L-L./ubuntu/lib/x86_64-linux-gnu
-L./ubuntu/usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a
-L./ubuntu/usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1
-L./ubuntu/lib/x86_64-linux-gnu/libc.so.6
-L./ubuntu/usr/lib/x86_64-linux-gnu/libc_nonshared.a
-L./ubuntu/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
-L-dynamic-linker -L/lib64/ld-linux-x86-64.so.2 -v hello.d
[2]
root at 84eb0783a80b:/prj# ./hello
Trace/breakpoint trap
root at 84eb0783a80b:/prj# gdb ./hello
<snip>
(gdb) r
Starting program: /prj/hello
warning: Error disabling address space randomization: Operation
not permitted
warning: Could not trace the inferior process.
Error:
warning: ptrace: Operation not permitted
During startup program exited with code 127.
[3]
https://forum.dlang.org/thread/bxzlendtgbfxodtmpzdf@forum.dlang.org
More information about the Digitalmars-d
mailing list