Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 447
juniel_katarn Avatar asked May 22 '17 06:05

juniel_katarn


2 Answers

If the only reason to use LLVM-lld is speed, then try zld

  • https://github.com/michaeleisel/zld/

It's consistently cuts time to half (often to less than half) as compared to that taken by Apple-ld.

Add the following linker flag:

-fuse-ld=`which zld` -Wl,-zld_original_ld_path,ld 
like image 162
puio Avatar answered Oct 17 '22 06:10

puio


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.

like image 1
juniel_katarn Avatar answered Oct 17 '22 07:10

juniel_katarn