昨天写了一篇 Mac 上为 doom-emacs 安装 irone-server 的详细步骤,随着后来对配置的逐渐了解,发现不用那么麻烦,只要把环境变量设置好就可以成功编译。首先安装好 cmake 和 llvm(llvm 非常大,且要编译,时间非常长,耐心等候^_^):

1
brew install cmake llvm

在 doom-emacs 里执行 M-x irony-install-server,会提示执行命令(各有路径有所区别):

1
2
3
cmake -DCMAKE_INSTALL_PREFIX=/Users/yaohui/.emacs.d.doom/.local/etc/irony-server/
/Users/yaohui/.emacs.d.doom/.local/packages/elpa/irony-20190703.1732/server
             && cmake --build . --use-stderr --config Release --target install

我们在 cmake 后面加上环境变量

1
2
3
4
-DCMAKE_PREFIX_PATH=/usr/local/opt/llvm
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON
-DLIBCLANG_INCLUDE_DIR=/usr/local/opt/llvm/include
-DLIBCLANG_LIBRARY=/usr/local/opt/llvm/lib/libclang.dylib

完成后的编译命令为:

1
2
3
4
5
6
7
cmake -DCMAKE_INSTALL_PREFIX=/Users/yaohui/.emacs.d.doom/.local/etc/irony-server/
-DCMAKE_PREFIX_PATH=/usr/local/opt/llvm
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON
-DLIBCLANG_INCLUDE_DIR=/usr/local/opt/llvm/include
-DLIBCLANG_LIBRARY=/usr/local/opt/llvm/lib/libclang.dylib
/Users/yaohui/.emacs.d.doom/.local/packages/elpa/irony-20190703.1732/server
             && cmake --build . --use-stderr --config Release --target install

即可正常编译。

另外,也可以用 xcode 的 libclang.dylib,编译命令为:

1
2
3
4
5
6
cmake -DCMAKE_INSTALL_PREFIX=/Users/yaohui/.emacs.d.doom/.local/etc/irony-server/
-DCMAKE_PREFIX_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON -DLIBCLANG_INCLUDE_DIR=/usr/local/opt/llvm/include
-DLIBCLANG_LIBRARY=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib
/Users/yaohui/.emacs.d.doom/.local/packages/elpa/irony-20190703.1732/server
             && cmake --build . --use-stderr --config Release --target install

**注意:这里为了展示效果,把命令进行了换行,在实际执行时要在一行内。**