c++macoslinkerllvmlld

LLD - unknown argument: -arch


Trying to link a simple program using LLVM 4.0.0 release (Clang, LLD) on Mac OS Sierra. Note, this is fully achievable in Linux.

My current path is prefixed with the LLVM's bin directory (i.e. /opt/LLVM/4.0.0/bin:$PATH.

The program (main.cpp) is the simplest possible C++ application:

int main()
{
    return 0;
}

The shell command issued is: clang -fuse-ld=lld.
This fails with these errors:

/opt/llvm/4/bin/ld.lld: error: unknown argument: -no_deduplicate
/opt/llvm/4/bin/ld.lld: error: unknown argument: -dynamic
/opt/llvm/4/bin/ld.lld: error: unknown argument: -arch
/opt/llvm/4/bin/ld.lld: error: unknown emulation: acosx_version_min
/opt/llvm/4/bin/ld.lld: error: unable to find library -lto_library
/opt/llvm/4/bin/ld.lld: error: /opt/llvm/4/lib/libLTO.dylib: invalid data encoding
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

Using the -v switch, I see this linker command (formatted):

"/opt/llvm/4/bin/ld.lld" \
    -demangle \
    -lto_library /opt/llvm/4/lib/libLTO.dylib \
    -no_deduplicate \
    -dynamic \
    -arch x86_64 \
    -macosx_version_min 10.12.0 \
    -o a.out \
    main.o \
    -lSystem /opt/llvm/4/bin/../lib/clang/4.0.0/lib/darwin/libclang_rt.osx.a

Does anyone know the proper switches for this platform?


Solution

  • After contacting the LLVM-dev mailing list, it appears that LLD for macOS (meaning, Mach-O object format linking) development is stale.

    To use Clang on macOS, it's best to stick with the OS-provided ld64.