Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking with LLVM LLD does not work [macos]

Tags:

c++

llvm

clang

lld

The following compile command with clang6.0:

LDFLAGS="-L/usr/local/opt/myllvm6.0rc1/lib -fuse-ld=lld" 
CPPFLAGS="-I/usr/local/opt/myllvm6.0rc1/include -I/usr/local/opt/myllvm6.0rc1/include/c++/v1/"; 
clang++ -fsanitize=address $LDFLAGS $CPPFLAGS -g -v main.cpp

gives:

 "/usr/local/opt/myllvm6.0rc1/bin/ld64.lld" -demangle -lto_library /usr/local/opt/myllvm6.0rc1/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o a.out -L/usr/local/opt/myllvm6.0rc1/lib /var/folders/14/rc46ppds1ms2kj_mvdcxlc040000gn/T/main-113675.o -lc++ /usr/local/opt/myllvm6.0rc1/lib/clang/6.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib -rpath @executable_path -rpath /usr/local/opt/myllvm6.0rc1/lib/clang/6.0.0/lib/darwin -lSystem /usr/local/opt/myllvm6.0rc1/lib/clang/6.0.0/lib/darwin/libclang_rt.osx.a
warning: ignoring unknown argument: -no_deduplicate
warning: -sdk_version is required when emitting min version load command.  Setting sdk version to match provided min version
Unable to find library for -lto_library
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

I dont understand why it cant load the /usr/local/opt/myllvm6.0rc1/lib/libLTO.dylib (it exists at this location!) Any idea?

like image 414
Gabriel Avatar asked Nov 08 '22 10:11

Gabriel


1 Answers

You are using -fuse-ld=lld which is what the LLD documentation says to do and as you can see ld64.lld is being run. However, the flag -no_deduplicate is not an lld flag; it is an OSX ld flag. The ld64.lld man page is here:

https://manpages.ubuntu.com/manpages/disco/man1/ld.lld.1.html

like image 77
Olsonist Avatar answered Nov 14 '22 21:11

Olsonist