After not using Mathematica for a few months (I think since december 2018) on my MacBook Pro from 2013 (now with macOS Mojave 10.14.5) I am suddenly facing issues with Compile. I've installed the latest Xcode and agreed to the license terms, but I still get the error:

CCompilerDriver`CreateLibrary::cmperr: "Compile error: clang: error: linker command failed with exit code 1 (use -v to see invocation)

Compile::nogen: A library could not be generated from the compiled function.

when I try to do even a trivial

Compile[{{x, _Real}}, x*x, CompilationTarget -> "C"]

Any tips on how to debug or a known solution?


After doing

Compiler`$CCompilerOptions = {"ShellOutputFunction" -> Print};

I see the message

clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]

ld: library not found for -lstdc++

I'm guessing this last error is (part of) the crux of the matter.


I tried to change the compiler from clang to gcc but I don't think Compile noticed (?): I did

$CCompiler = CCompilerDriver`GCCCompiler`GCCCompiler;


but when I run the Compile line above, I still get clang-related errors...

  • $\begingroup$ If the XCode installation is younger than Mathematica's then Mathematica might have a problem with detecting it correctly. Have you tried to kust reinstall Mathematica? $\endgroup$ Jul 22, 2019 at 14:20
  • 1
    $\begingroup$ @HenrikSchumacher, no worries, thanks for reading my post :) Here's hoping Szabolcs will see the post, I have a hunch he has been dealing with this :P $\endgroup$ Jul 22, 2019 at 14:35
  • 1
    $\begingroup$ Best way to make sure that he reads it: @Szabolcs! ;) $\endgroup$ Jul 22, 2019 at 14:54
  • 3
    $\begingroup$ This is due to Apple removing libstdc++. You may need to change CCompilerDriver`ClangCompiler`Private`dllLinkLibs["MacOSX-x86-64"] to use -lc++ instead of -lstdc++ $\endgroup$
    – ilian
    Jul 22, 2019 at 15:28
  • 2
    $\begingroup$ Could be done in init.m I think, just load CCompilerDriver first $\endgroup$
    – ilian
    Jul 22, 2019 at 17:13

1 Answer 1


Summarizing the comments into an answer:

As of version 10.4.0, CCompilerDriver will link to libc++ on Mac by default.

Earlier versions, however, link to libstdc++ and will run into this problem, because that library is no longer available (Apple deprecated it in Xcode 8 and finally removed it in Xcode 10).

The issue can be worked around by setting the following variables, used when linking executables and dynamic libraries respectively


CCompilerDriver`ClangCompiler`Private`dllLinkLibs["MacOSX-x86-64"] = "-lc++";
CCompilerDriver`ClangCompiler`Private`exeLinkLibraries["MacOSX-x86-64"] = "-lm -lpthread -lc++";

It may be convenient to place the above code in the kernel's init.m file so compilation works in every session.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.