[llvm-dev] ld.lld on MacOS question
Peter Kriens via llvm-dev
llvm-dev at lists.llvm.org
Thu Apr 27 09:05:09 PDT 2017
Hopefully the right list … otherwise pointers appreciated (I’ve spent days trying to find a solution but could not find sufficient documentation, could not find a proper list of -flavor darwin commands)
I am setting up an environment for cross compiling shared libraries using LLVM. Overall this works perfectly for many unix like environments but MacOS is a pain in the ass despite that I am running on MacOS. (I’ve not tried windows yet.)
I seem to be able to compile with clang a proper mach object file for a hello function. However, when I link this function into a shared library I (surprisingly for a shared lib?) get undefined symbols like _printf, stub runtime: dyld_stub_binder, _main, etc. Using the flag
I get no errors or warnings but then when I try to link the shared library to a main program I get the error:
ld: malformed dylib has MH_NO_REEXPORTED_DYLIBS flag
but no LC_REEXPORT_DYLIB load commands: ./libhello.dylib file './libhello.dylib'
I’ve included the shell file that makes the hello shared lib and the command that I use to link the file.
Thanks for any help, this looks like an amazing solution if it can get to work on all supported platforms.
$ /usr/local/Cellar/llvm/4.0.0_1/bin/clang \
-target x86_64-apple-darwin16.5.0 \
$ file hello.o
hello.o: Mach-O 64-bit object x86_64
$ /usr/local/Cellar/llvm/4.0.0_1/bin/ld.lld \
-flavor darwin \
-sdk_version 10.5.0 \
-arch x86_64 \
-undefined dynamic_lookup \
-o libhello.dylib \
$ file libhello.dylib
libhello.dylib: Mach-O 64-bit dynamically linked shared library x86_64
$ gcc x.c -L. -lhello
ld: malformed dylib has MH_NO_REEXPORTED_DYLIBS flag but no LC_REEXPORT_DYLIB load commands: ./libhello.dylib file ‘./libhello.dylib'
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev