title: How can I make macOS frameworks available to clang in a Nix environment?
body: <p>I'm on macOS 10.13.5, learning to program Rust, and I use Nix to control my development environment.</p>
  
  <p>Some actions, such as including the <code>jsonwebtoken</code> library or installing the  <code>cargo-watch</code> module, cause a build that requires a macOS framework that appears to not be installed. I get this error message:</p>
  
  <pre class="lang-none prettyprint-override"><code>  = note: ld: framework not found CoreServices
            clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
  
  error: aborting due to previous error
  
  error: failed to compile `cargo-watch v6.0.0`, intermediate artifacts can be found at `/var/folders/13/84dj8yr54_1c_pn0s8n7444h0000gn/T/cargo-install.lYPZaEduUBdu`
  
  Caused by:
    Could not compile `cargo-watch`.
  </code></pre>
  
  <p>This is an abbreviated version of the clang command that fails:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: linking with `/nix/store/9j864incgjx7kqggbpisdi3nmssy4qm5-clang-wrapper-5.0.2/bin/cc` failed: exit code: 1
    |
    = note: "/nix/store/9j864incgjx7kqggbpisdi3nmssy4qm5-clang-wrapper-5.0.2/bin/cc" "-m64" "-L" ... "/nix/store/rfp87664xzhl6zv7dx5c1hixasqfxkp4-rustc-1.24.0/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-ba331b20e371c580.rlib" "-framework" "CoreServices" "-framework" "CoreServices" "-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m"
  </code></pre>
  
  <p>The only thing that I have found to try was to add frameworks to my PATH, but either that answer is wrong or the PATH environment variable isn't able to go through cargo all the way to where I'm doing the build in question.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/16387484/clangllvm-compile-with-frameworks">Clang(LLVM) compile with frameworks</a></li>
  <li><p><a href="https://discussions.apple.com/thread/3754858" rel="noreferrer">How to specify framework in clang? - Apple Community</a></p></li>
  <li><p>Rust: 1.24.0</p></li>
  <li>Cargo: 0.25.0</li>
  <li>jsonwebtoken: 0.4.0</li>
  <li>cargo-watch: default version from <code>cargo install cargo-watch</code></li>
  </ul>
  
  <p>How do I tell clang where to look for the frameworks? Does it involve a change to my working environment, or do I need to be looking into changing the build process for the crates that I want to install?</p>
  
  <h1>More information</h1>
  
  <p>I discovered the <code>clang -Xlinker -v</code> command, and the output is quite interesting:</p>
  
  <pre><code>@(#)PROGRAM:ld  PROJECT:ld64-274.2
  configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
  Library search paths:
      /nix/store/ql6xbmdplca4sjpk0pz647p7djzri03c-libc++-5.0.2/lib
      /nix/store/rfp87664xzhl6zv7dx5c1hixasqfxkp4-rustc-1.24.0/lib
      /nix/store/ql6xbmdplca4sjpk0pz647p7djzri03c-libc++-5.0.2/lib
      /nix/store/rfp87664xzhl6zv7dx5c1hixasqfxkp4-rustc-1.24.0/lib
      /nix/store/8ykfqv6jx9jvfhnc4cdygdzg0piy8253-Libsystem-osx-10.11.6/lib
      /nix/store/4papfih2r9xlsl9m7hlisparij8k9zaq-clang-5.0.2-lib/lib
  Framework search paths:
      /nix/store/hc6d711vwlwnn9swmkdpi9nbswbqg6h0-CF-osx-10.10.5/Library/Frameworks
      /nix/store/hc6d711vwlwnn9swmkdpi9nbswbqg6h0-CF-osx-10.10.5/Library/Frameworks
  Undefined symbols for architecture x86_64:
    "_main", referenced from:
       implicit entry/start for main executable
  ld: symbol(s) not found for architecture x86_64
  clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>This seems to point to things missing from my Nix shell and not the operating system or even <code>clang</code> itself.</p>