I was hoping you guys could point me in the right direction, since I have not yet fully connected all the dots.
Problem statement: I have to maintain an ancient, mainly C project which in the past was simply developed using vi and Makefiles, which compiled with gcc (actually g++, because there are some C++ files). Now I am busy constructing this project using CodeLite and one of my main desires is to have a working language server using clangd to easily navigate and explore the code base. I am currently struggling to configure clangd to find all the project headers.
What I have done so far:
create a few Codelite projects to organise the main application suite and the libraries
there are already old school Makefiles for the entire project, so in Codelite I am using a custom build (Project settings -> Customize -> Custom Build)
I played around with the clangd server settings (Plugins -> Language Server -> Settings -> clangd), but did not make much progress
I tried automatically creating the compile_commands.json file (Settings -> Code Completion -> Generate compile_commands.json file), did not seem to work
I tried to manually create the compile_commands.json and compile_flags.txt, but I am not too sure where to place them
Questions:
what is in general the best practice for configuring clangd with Codelite?
in my particular case (gcc + custom Makefiles), how should I create compile_commands.json and compile_flags.txt? I saw a tool called bear that helps with this
You need only one of compile_commands.json and compile_flags.txt
If I remember correctly compile_flags.txt take precedence when found in same directory.
That file should be placed in source directory or any of its parent (the first one found is used).
Codelite generate them normally near project/workspace (I don't used custom Makefiles, so don't know the behavior for that),
so not necessary to the correct place depending of your directories structure.
clang tooling use also files (.clangd, .clang-format, ...) for per directory (and so potentially per project) options.
,
The easiest way is to create a file named (like Jarod42 mentioned) compile_flags.txt
place this file at the root level of your workspace and it should have a content similar to this:
Have a workspace and project created in codelite.
After compiling, the Makefile is overwritten and no errors reported.
But, the compile does not produce the executable.
Last edited by oneno on Tue Jan 03, 2023 2:01 pm, edited 2 times in total.
It appears there is a bug in the codelite configuration.
To resolve the issue, all codelite configuration files were deleted via file manager (Thunar on linux) via Ctrl+h and deleting the hidden .codelite folder.
After;
launched codelite IDE
dragged the project folder in codelite just above where it says "DRAG AND DROP A FOLDER HERE" and choosing C++. That created the workspace and project.
buiilt the project and compiled the executable which ran as required.
But noticed the Makefile was overwritten. Before and after of the Makefile are on pastebin
So have codelite compile the source as required. But Makefile is being overwritten ?
Last edited by oneno on Wed Jan 04, 2023 3:02 am, edited 1 time in total.