Haiku clangd troubles

Posted on 2022-04-05

Back to index

💬 Introduction

I have had some trouble setting up Clangd+Kakoune+Kak-lsp on Haiku x86_gcc2 for a simple C++ project. I'm using clangd from the llvm12_x86_clang package.

The project looks like

// --> App.h
#pragma once
#include <Application.h>

class App : public BApplication {

// --> App.cpp
#include "App.h"

  : BApplication("application/x-vnd.tobik.app")

with the following compile_commands.json generated by CMake (configured with the default compiler inside setarch x86):

  "directory": "/boot/home/src/codeberg.org/tobik/app/_build",
  "command": "/boot/system/bin/x86/c++ -o src/CMakeFiles/app.dir/App.cpp.o -c /boot/home/src/codeberg.org/tobik/app/src/App.cpp",
  "file": "/boot/home/src/codeberg.org/tobik/app/src/App.cpp"

🔍 Search path troubles

Clangd will show this diagnostic

## Diagnostics
* In included file: 'new' file not found
  note: error occurred here

So that seems like a good excuse to use Haiku's excellent query capabilities instead of using find on the command line. Since we know the exact name we can do a search by attribute -> Name -> is -> new.

It appears that it's available under /boot/system/develop/tools/x86/lib/gcc/i586-pc-haiku/11.2.0/include/c++/new. Clangd seems to be missing some include paths.

Switching the build to Clang did not work. That's a problem for another day. Since we aren't trying to link the application with Clang it shouldn't be a problem to just tell clangd to index the GCC headers too.

GCC has these default paths that Clang does not have

$ setarch x86 g++ -v -c -xc++ /dev/null

⚙ ️Clangd config

We can create ~/config/settings/clangd/config.yaml to tell clangd about them:

    - -isystem/boot/system/develop/tools/x86/bin/../lib/gcc/i586-pc-haiku/11.2.0/include/c++
    - -isystem/boot/system/develop/tools/x86/bin/../lib/gcc/i586-pc-haiku/11.2.0/include/c++/i586-pc-haiku
    - -isystem/boot/system/develop/tools/x86/bin/../lib/gcc/i586-pc-haiku/11.2.0/include/c++/backward
    - -isystem/boot/system/develop/tools/x86/bin/../lib/gcc/i586-pc-haiku/11.2.0/include
    - -isystem/boot/system/develop/tools/x86/bin/../lib/gcc/i586-pc-haiku/11.2.0/include-fixed

Problem solved for now and moving on... but with code navigation and autocomplete!

This document is also available on Gemini: gemini://tobik.me/2022/04/05/haiku-clangd.gmi