[llvm-dev] ld.lld ignoring --sysroot
Ivan Medoedov via llvm-dev
llvm-dev at lists.llvm.org
Wed May 13 19:04:23 PDT 2020
Hello,
I'm trying to compile a Linux hello world executable on macOS.
The first step is simple:
clang -c -target x86_64-linux-gnu -c -o hello.o hello.c
But linking results in an error:
ld.lld --sysroot=/linuxroot/ -o hello -m elf_x86_64 \
-dynamic-linker /lib64/ld-linux-x86-64.so.2 \
/lib/crt1.o \
/usr/lib/x86_64-linux-gnu/crti.o ../hello.o \
/usr/lib/x86_64-linux-gnu/libc.so \
/usr/lib/x86_64-linux-gnu/crtn.o
ld.lld: error: cannot open /lib/crt1.o: No such file or directory
ld.lld: error: cannot open /usr/lib/x86_64-linux-gnu/crti.o: No such file
or directory
/linuxroot/ contains all the necessary files copied from a Linux machine:
/linuxroot/lib/crt1.o, /linuxroot/usr/lib/x86_64-linux-gnu/crti.o, etc
It works if I use a full path for each file (-dynamic-linker
/linuxroot/lib64/ld-linux-x86-64.so.2 ...), but the resulting binary
doesn't work on Linux, because it's dynamically linked to /linuxroot/...
which is missing on the Linux box.
file hi
hi: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically
linked, interpreter /linuxroot/lib64/ld-linux-x86-64.so.2, for GNU/Linux
3.2.0, not stripped
The only way I can make it work is to have actual
/usr/lib/x86_64-linux-gnu/crti.o etc on my macOS box, which --sysroot is
supposed to help avoid.
I'm sure I'm missing something simple here. I've been following the docs,
but couldn't figure it out on my own.
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200514/0606f3bc/attachment.html>
More information about the llvm-dev
mailing list