Skip to content

Mac OS X issues and workaround

George O'Hara edited this page Apr 13, 2020 · 3 revisions

Via Homebrew (Catalina, 2020)

I had difficulties getting the irony-mode server to install (LibClang couldn't be found), and found that running brew install llvm (this can take a very long time to execute) and then inserting -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm as the first argument of the first cmake command that appears in the Emacs minibuffer after executing M-x irony-install-server worked.

re-use Xcode libclang

Download a pre-compiled package from llvm.org

Change the 3.5.0 version with the latest (the greatest!).

  1. Download clang+llvm-3.5.0-macosx-apple-darwin.tar.xz from http://llvm.org/releases/download.html
  2. Extract it somewhere (e.g: /tmp)
  3. make a clean build directory
  4. run cmake -DCMAKE_PREFIX_PATH=/tmp/clang+llvm-3.5.0-macosx-apple-darwin/ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \</path/to/irony-mode/server/\>
  5. build and run make && ./bin/irony-server --version

Download the missing headers corresponding to the Xcode version

irony-server compiles and works on OSX Yosemite with standard libclang from Xcode7. The only piece missing is clang-c header files, which may be borrowed from llvm 3.8.

Quick and dirty way to build irony-server on Yosemite with Xcode7

### create /usr/local if not there yet
sudo mkdir -p /usr/local/lib /usr/local/include
### grab standard libclang
sudo cp -p "`xcode-select --print-path`"/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib /usr/local/lib
### (dirty part) supplement with latest llvm clang-c includes
cd /tmp
svn export http://llvm.org/svn/llvm-project/cfe/trunk/include/clang-c/
sudo cp -RP clang-c /usr/local/include

M-x irony-install-server RET should give you no trouble after that. Compiles and works.

One more step required on OSX - need to find where Xcode keeps all header files to add them to your .clang_complete. Otherwise irony is useless.

Peek at what Apple compiler uses

echo | clang -x c++ -v -E - 2>&1 | sed -n '/^#include </,/^End/s|^[^/]*\([^ ]*/include[^ ]*\).*$|-I\1|p'

Add them to your .clang_complete:

$ cat .clang_complete
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include
...

Adding to irony-additional-clang-options should work as well

Source:

Homebrew package

It looks like the LLVM package from Homebrew may be broken as found by issue #135.

The error appears as follow:

CMake Warning at cmake/CheckLibClangBuiltinHeadersDir.cmake:87 (message):
  CheckLibClangBuiltinHeadersDir: unsupported configuration, please report.



    Check with args: -isystem;"/usr/local/Cellar/llvm/3.5.0/lib/clang/3.5.0/include";/Users/Chester/.emacs.d/irony/build/CMakeFiles/CMakeTmp/check-libclang-stddef.cpp
    Check output:
      dyld: Library not loaded: @rpath/libLLVM-3.5.dylib
    Referenced from: /usr/local/opt/llvm/lib/libclang.dylib
    Reason: image not found

  SIGTRAP

The fix found in this issue is to do:

$ cd /usr/local/opt/llvm/lib
$ sudo install_name_tool -change @rpath/libLLVM-3.5.dylib /usr/local/opt/llvm/lib/libLLVM-3.5.dylib /usr/local/opt/llvm/lib/libclang.dylib

Please refer to this page the Homebrew issue #34169 to track this problem.