title: Using -fuse-ld=lld with Clang on macOS
body: <p>I am using Clang 10 (not AppleClang) on macOS 10.15 and am trying to link with LLD by specifying <code>-fuse-ld=lld</code> in the CMake flags <code>CMAKE_EXE_LINKER_FLAGS</code>.</p>
  
  <p>However, I am getting the following error when I try to use LLD:</p>
  
  <pre><code>The C++ compiler
  
  "/Users/XXX/llvm/bin/clang++"
  
  is not able to compile a simple test program.
  
  It fails with the following output:
  
  ld64.lld: warning: ignoring unknown argument: -platform_version
  ld64.lld: warning: ignoring unknown argument: -search_paths_first
  ld64.lld: warning: ignoring unknown argument: -headerpad_max_install_names
  ld64.lld: warning: -sdk_version is required when emitting min version load command.  Setting sdk version to match provided min version
  ld64.lld: error: Unable to find library for -lc++
  clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
  make[1]: *** [cmTC_0d561] Error 1
  make: *** [cmTC_0d561/fast] Error 2
  </code></pre>
  
  <p>Here is my program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  
  int main()
  {
      std::cout &lt;&lt; "Hello World!" &lt;&lt; std::endl;
  
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>Here is my CMakeLists.txt file:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
  
  set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
  
  project(test VERSION 2.0 LANGUAGES CXX)
  
  add_executable(testprog "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
  </code></pre>
  
  <p>Here is my bash script to launch CMake:</p>
  
  <pre><code>#!/bin/bash
  
  root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &amp;&amp; pwd )"
  
  sys_root="/Users/XXX/macOS-sdks/MacOSX10.13.sdk"
  cmake_bin_path="/Applications/CMake.app/Contents/bin"
  llvm_bin="/Users/XXX/llvm/bin"
  
  function add_search_path() {
      if [ -d "$1" ] &amp;&amp; [[ ":$PATH:" != *":$1:"* ]]; then
          PATH="${PATH:+"$PATH:"}$1"
      fi
  }
  
  add_search_path $cmake_bin_path
  add_search_path $llvm_bin
  
  cd "${root}/build"
  
  cmake -DCMAKE_OSX_SYSROOT=${sys_root} \
        -DCMAKE_C_COMPILER="${llvm_bin}/clang" \
        -DCMAKE_CXX_COMPILER="${llvm_bin}/clang++" \
        -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
        -DCMAKE_OSX_ARCHITECTURES=x86_64 \
        -DCMAKE_BUILD_TYPE=Debug ..
  
  cores=`sysctl -n hw.physicalcpu`
  
  cmake --build "${root}/build" --target all -- -j ${cores}
  
  ./testprog
  </code></pre>