I'm using vim with YouCompleteMe (YCM) plugin for C programming. YCM needs a json file to show code completion suggestions or a manually crafted .ycm_extra_conf.py
file.
Build systems like cmake
and ninja
provide a switch to generate the json file while building but there is no such option for make
. bear is a utility to generate the JSON compilation database.
How can I integrate bear
with my Makefile
? Should I call make all
in which bear is an external utility or should I instead call bear make
? I'm a little confused by its guide.
For example, here is the a basic example of GTK+. I can compile the code using gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0`
.
How can I automate the process of 1- compiling and 2- creating the json file if I want to use make
as my build system? What should be in my Makefile
?
Thanks
You need to feed bear
every command you use to build from source. For example, you require configure
script to be run before make
, first do bear ./configure
then bear make
. Make sure the source folder used to build is not processed earlier with some script (like configure
) because it may affect the json file contents.
If you aren't able to install Bear or compiledb easily, maybe a web app is an option.
I've built a simple web app to generate compile_commands.json
, all you need to have is the output of make
, e.g., make --print-directory -n
. The web app is https://texttoolkit.com/compilation-database-generator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With