1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【emacs】company-ironyを導入してC言語補完環境を構築

Posted at

ironyサーバーのビルドに失敗したので、その備忘録。

環境

macOS Mojava 10.14.6
GNU Emacs 26.3

company-irony導入までの手順

ここは今回の主題ではないので、簡潔に(間違った箇所があるかも)。

まず必要なパッケージは以下で全部なはず。
company, irony, company-irony

例えば設定としては(.emacsなどに記述)


;; companyとcompany-ironyを連携させる
(with-eval-after-load 'company
  (add-to-list 'company-backends 'company-irony))
;; Cファイルを開いたときにcompany, ironyモードが起動するようにする
(add-hook 'c-mode-hook lambda()(
    ('company-mode)
    ('irony-mode)
))

設定は以上だが、初回に


M-x irony-install-server

を実行する必要がある。
returnを押すと以下が実行されることを確認してきて、再びreturnで実行される。

cmake -DCMAKE_INSTALL_PREFIX\=/Users/myname/.emacs.d/irony/  /Users/myname/.emacs.d/elpa/irony-1.4.0/server && cmake --build . --use-stderr --config Release --target install

ここでエラーが出た。

cmakeでエラー

エラーは以下のような内容。

Could NOT find LibClang (missing: LIBCLANG_LIBRARY LIBCLANG_INCLUDE_DIR)

解決策

まずbrew install llvmでllvmをインストール。
ただしmacだと自動でこのllvmを見に行ってくれないらしい。

インストールされた場所を確認すると/usr/local/opt/llvmをリンクすればいいらしい。


$ brew info llvm
llvm: stable 11.0.0 (bottled), HEAD [keg-only]
Next-gen compiler infrastructure
https://llvm.org/
/usr/local/Cellar/llvm/11.0.0 (8,922 files, 1.3GB)
  Poured from bottle on 2021-01-16 at 18:53:48
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/llvm.rb
License: Apache-2.0
==> Dependencies
Build: cmake ✘, python@3.9 ✘
Required: libffi ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
<以下略>

ということで、cmakeする際に-DCMAKE_PREFIX_PATH=/usr/local/opt/llvmというフラグを追加するとうまくいった。

チャンチャン。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?