Ivan Medoedov via llvm-dev
2019-Jun-07 18:19 UTC
[llvm-dev] ld.lld fails with "undefined symbol: _fopen" on macOS, while working as expected on Linux
Hi, I'm trying to cross-compile my app. #include <stdio.h> int main() { puts("test"); fopen("test", "r"); // removing fopen() call removes the error return 0; } clang -c -target x86_64-linux-gnu test.c ld.lld -v -o test -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o test.o /usr/lib/x86_64-linux-gnu/libc.so /usr/lib/x86_64-linux-gnu/crtn.o This works fine on Linux, but when I run the same command on macOS, I get LLD 8.0.0 (compatible with GNU linkers) ld.lld: error: undefined symbol: _fopen>>> referenced by fopen.c >>> test.o:(main)I haven't set up --sysroot yet, I just copied all these files from the Linux machine for now. This only happens with fopen(). Using puts() or printf() is fine. LLVM version is 8.0.0. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190607/595e9293/attachment.html>
Tim Northover via llvm-dev
2019-Jun-07 19:34 UTC
[llvm-dev] ld.lld fails with "undefined symbol: _fopen" on macOS, while working as expected on Linux
Hi Ivan, On Fri, 7 Jun 2019 at 11:19, Ivan Medoedov via llvm-dev <llvm-dev at lists.llvm.org> wrote:> LLD 8.0.0 (compatible with GNU linkers) > ld.lld: error: undefined symbol: _fopen > >>> referenced by fopen.c > >>> test.o:(main)I suspect you're getting the macOS version of stdio.h, which makes fopen some kind of alias. You really should use a sysroot when cross-compiling, though you *might* get away with just -I/path/to/linux/usr/include. Just what you've copied across might well be sufficient to use with --sysroot. Cheers. Tim.
Ivan Medoedov via llvm-dev
2019-Jun-07 20:44 UTC
[llvm-dev] ld.lld fails with "undefined symbol: _fopen" on macOS, while working as expected on Linux
Thanks, Tim. You are right, it's using macOS' stdio.h, which is a terrible idea. Clang docs on --sysroot: When you have extracted your cross-compiler from a zip file into a directory, you have to use --sysroot=<path>. The path is the root directory where you have unpacked your file, and Clang will look for the directories bin, lib, include in there. I have a silly question: where can I download the mentioned zip file with all bin, lib, and include files for x64 Linux target? So far I've been copying files one by one (/lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o, etc) and it's been a painful process. On Fri, Jun 7, 2019 at 9:34 PM Tim Northover <t.p.northover at gmail.com> wrote:> Hi Ivan, > > On Fri, 7 Jun 2019 at 11:19, Ivan Medoedov via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > LLD 8.0.0 (compatible with GNU linkers) > > ld.lld: error: undefined symbol: _fopen > > >>> referenced by fopen.c > > >>> test.o:(main) > > I suspect you're getting the macOS version of stdio.h, which makes > fopen some kind of alias. You really should use a sysroot when > cross-compiling, though you *might* get away with just > -I/path/to/linux/usr/include. Just what you've copied across might > well be sufficient to use with --sysroot. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190607/902259a6/attachment.html>
Possibly Parallel Threads
- ld.lld fails with "undefined symbol: _fopen" on macOS, while working as expected on Linux
- ld.lld ignoring --sysroot
- ld.lld ignoring --sysroot
- Cross compiling an empty program results in a segfault
- [LLVMdev] Changes to Debian's linker object files breaks building LLVM [crti.o, crt1.o, crtn.o]