1

I am currently trying to setup a .clangd file to use for my lsp ...

how can i add multiple compile flags? my file is autogenerated and looks like this:

CompileFlags:
Add:
    - -IC:\Users\adria\Desktop\Nimble_New\include
    - -IC:\Users\adria\Desktop\Nimble_New\include\lua
    - -IC:\Users\adria\Desktop\Nimble_New\include\raylib
    - -IC:\Users\adria\Desktop\Nimble_New\include\rlimgui
    - -IC:\Users\adria\Desktop\Nimble_New\include\rlimgui\extras
    - -IC:\Users\adria\Desktop\Nimble_New\src
    - -IC:\Users\adria\Desktop\Nimble_New\src\asseteditor
    - -IC:\Users\adria\Desktop\Nimble_New\src\textureeditor
    - -IC:\Users\adria\Desktop\Nimble_New\src\ui
    - -IC:\Users\adria\Desktop\Nimble_New\src\utils

I also tried it this way:

CompileFlags:
Add: [-IC:\Users\adria\Desktop\Nimble_New\include,-IC:\Users\adria\Desktop\Nimble_New\include\lua,-IC:\Users\adria\Desktop\Nimble_New\include\raylib,-IC:\Users\adria\Desktop\Nimble_New\include\rlimgui,-IC:\Users\adria\Desktop\Nimble_New\include\rlimgui\extras,-IC:\Users\adria\Desktop\Nimble_New\src,-IC:\Users\adria\Desktop\Nimble_New\src\asseteditor,-IC:\Users\adria\Desktop\Nimble_New\src\textureeditor,-IC:\Users\adria\Desktop\Nimble_New\src\ui,-IC:\Users\adria\Desktop\Nimble_New\src\utils]

If i do:

CompileFlags:
    Add: -IC:\Users\adria\Desktop\Nimble_New\include\raylib

Or:

CompileFlags:
    Add: 
        - -IC:\Users\adria\Desktop\Nimble_New\include\raylib

it works just fine for one include path but as soon as i add another one it doesnt load anymore.

Is there another solution to this?

2 Answers 2

1

It's important for Add: to be indented relative to CompileFlags:.

Either of your first two examples should work with that change, for example:

CompileFlags:
    Add:
        - -IC:\Users\adria\Desktop\Nimble_New\include
        - -IC:\Users\adria\Desktop\Nimble_New\include\lua
        - -IC:\Users\adria\Desktop\Nimble_New\include\raylib
        - -IC:\Users\adria\Desktop\Nimble_New\include\rlimgui
        - -IC:\Users\adria\Desktop\Nimble_New\include\rlimgui\extras
        - -IC:\Users\adria\Desktop\Nimble_New\src
        - -IC:\Users\adria\Desktop\Nimble_New\src\asseteditor
        - -IC:\Users\adria\Desktop\Nimble_New\src\textureeditor
        - -IC:\Users\adria\Desktop\Nimble_New\src\ui
        - -IC:\Users\adria\Desktop\Nimble_New\src\utils

(If that still does not work, please post clangd logs for further diagnosis.)

Sign up to request clarification or add additional context in comments.

3 Comments

I indented it in my file. It just didnt indent when I copied it
@BigAgg Ok. I see you've found a workaround, but if you're still interested in finding out why the original approach doesn't work, please feel free to share logs as mentioned.
I will after this weekend. Got plenty to do for now but i will come back to this for sure thanks for pointing out the logging
0

I fixed it by creating a compile_flags.txt in the source directory which has following content:

-IC:\Users\adria\Desktop\Nimble_New\include
-IC:\Users\adria\Desktop\Nimble_New\include\lua
-IC:\Users\adria\Desktop\Nimble_New\include\raylib
-IC:\Users\adria\Desktop\Nimble_New\include\rlimgui
-IC:\Users\adria\Desktop\Nimble_New\include\rlimgui\extras
-IC:\Users\adria\Desktop\Nimble_New\src
-IC:\Users\adria\Desktop\Nimble_New\src\asseteditor
-IC:\Users\adria\Desktop\Nimble_New\src\textureeditor
-IC:\Users\adria\Desktop\Nimble_New\src\ui
-IC:\Users\adria\Desktop\Nimble_New\src\utils

simple as that i can use my lsp without problems with clangd

for anyone having the same issue i automated the creation of the file with a simple python file:

import os

dir_path = os.path.dirname(os.path.realpath(__file__))

include_paths = []

for path, subdirs, files in os.walk(f"{dir_path}\\include"):
    if path not in include_paths:
        include_paths.append(path)
for path, subdirs, files in os.walk(f"{dir_path}\\src"):
    if path not in include_paths:
        include_paths.append(path)

with open("compile_flags.txt", mode="w", encoding="utf-8") as file:
    for path in include_paths:
        file.write(f'-I{path}\n')

just run it in source dir, you can edit the folder paths "include" and "source" by your needs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.