Oni: How to configure clangd in macOS High Sierra?

Created on 24 Oct 2017  路  4Comments  路  Source: onivim/oni

I didn't know where to ask this question.

I'm using macOS High Sierra. I've installed clangd with the following commands:

  1. brew install llvm
  2. ln -s /usr/local/Cellar/llvm/5.0.0/include/c++ /usr/local/include

However it doesn't seem to work correctly. I've tested with the following C++ code:

#include <iostream>

int main() {
    std::cout << "hello\n";
}

It compiles fine but clangd shows the following error at the << operator:

invalid operands to binary expression ('std::__1::ostream' (aka 'int') and 'const char *')
bug help wanted language-integration

Most helpful comment

Thanks, I've had to install Command Line Tools, Xcode wasn't enough.

Below is a basic howto of the process. I've only copied the header files to minimize conflicts because the latest macOS uses llvm 4 and having multiple versions installed is not advised. Hopefully clangd will be included in the next version of macOS.

How to install clangd on macOS

  • Install the Command Line Tools with the following command: xcode-select --install
  • Download or build llvm.
  • Copy bin/clangd to /usr/local/bin/
  • Copy lib/clang/芦clang version禄/include to /usr/local/lib/clang/芦clang version禄/
  • Copy include/c++/v1 to /usr/include/c++/

All 4 comments

Unfortunately I'm not an expert on clangd - @TalAmuyal might have some ideas here. It does seem like there is some configuration issue - there is a compile_commands.json file that you can use to specify some options: https://reviews.llvm.org/D37150 - might be worth checking that out. Given that Oni is showing the error, it seems like the Oni piece of the integration is working.

Might be worth checking out this mailing list too (or posting the question there): http://lists.llvm.org/mailman/listinfo/cfe-dev

Let us know if you find anything, it would be great to add it to the wiki: https://github.com/bryphe/oni/wiki/Language-Support

Sorry for the late reply.

I tried your snippet, it seems to work well for me.
I'm using a version of clangd I compiled from source though, so a newer version of clangd might help.

Notes:

  1. Tried on Ubuntu.
  2. Might be a problem with system configs. ('std::__1::ostream' (aka 'int') looks really suspicious).

Thanks, I've had to install Command Line Tools, Xcode wasn't enough.

Below is a basic howto of the process. I've only copied the header files to minimize conflicts because the latest macOS uses llvm 4 and having multiple versions installed is not advised. Hopefully clangd will be included in the next version of macOS.

How to install clangd on macOS

  • Install the Command Line Tools with the following command: xcode-select --install
  • Download or build llvm.
  • Copy bin/clangd to /usr/local/bin/
  • Copy lib/clang/芦clang version禄/include to /usr/local/lib/clang/芦clang version禄/
  • Copy include/c++/v1 to /usr/include/c++/

Thanks @kuglee for sharing the steps you used to resolve it!

Was this page helpful?
0 / 5 - 0 ratings