Pengcheng的点点滴滴

路漫漫

Emacs 安装 irony (On Mac OS X)

简述

Emacs安装irony配合company-mode或者autocomplete我们便可以使C/C++, Obj-C代码自动补全。 在Mac OS X上安装irony-server你可以使用Port或者Homebrew安装Clang(LLVM)。 是如果我们已经安装有xcode则不必单独再安装clang. 仅仅需要libclang的头文件

首先确定安装Clang版本并下载Clang src

~$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

这里我们看到LLVM 版本为3.5。 我们到LLVM 3.5的Download Page下载Clang source code。 解开包后我们将cfe-3.5.0.src放入~/Download 稍后使用。

找到xcode的libclang

~$ echo "" | gcc -xc++ -E -v -
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -E -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.7 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/lee -ferror-limit 19 -fmessage-length 171 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o - -x c++ -
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin13.4.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 175 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
~$ ls /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/
arc                           libLTO.dylib                  libfunctionNameDemangle.dylib swift
clang                         libclang.dylib                sourcekitd.framework          swift_static

可以看到libclang 在*/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/*。

编译irony-server

建立一个build目录。

cmake -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON -DLIBCLANG_LIBRARY=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib -DLIBCLANG_INCLUDE_DIR=/Users/lee/Downloads/cfe-3.5.0.src/include/ -DCMAKE_INSTALL_PREFIX=/Users/lee/.emacs.d/irony/ /Users/lee/.emacs.d/elpa/irony-20150202.1453/server && cmake --build . --use-stderr --config Release --target install

在build/bin目录里我们就得到了irony-server。将irony-server复制到.emacs.d/irony/bin下,我们irony便可以正常工作了。

Comments

comments powered by Disqus