C++ mongodb development with nvim or Visual Studio Code in Fedora Linux

I watched this interesting Video from C++ creator Bjarne Stroustrup:

Learning and teaching modern C++.

In this video, Bjarne mentions what hard is to start interesting projects in C++ such as GUIs and Database development mainly because of lack of tools easy to use, specifically at 37:50 he stresses that for his undergrad students, when trying to do GUI development “the greatest problem was to get the GUI library installed”. “It is painful”.

Historically, C or C++ development has been difficult, add different compilers, operating systems, libraries, build systems and tools all of them different between them.

In this post I did a “quick” exercise to tests those sentences. My first try was to setup an environment to develop C++ with GTK+, spoiler alert: It was not quick, it was not easy even for me having experience in the C/C++ world. My second try was with mongodb library in Fedora Linux. In this post I will show the setup I have to work and be more productive with this “kind” of development. The first challenge was to get an editor providing intellisense auto completion and source code browsing

In previous posts I showed how to setup Neovim to provide C++ intellisense using Programming Language Server (PLS) with Coc plugin. I did not realize that for third party libraries you need to do further setup.

There are 2 ways to use intellisense for third party libraries with PLS and Coc plugin: clangd and ccls. I tried with ccls and I was not able to make it work, so I stuck with clangd. After many tries I got to use Intellisense with Neovim for mongodb libraries

Nvim coc-clangd. MondoDB intellisense..

I did the same for Visual Studio Code:

Visual Studio Code. MongoDB intellisense

I have used most of the time vi for code editing, but now we have more options, so I setup both nvim and Visual Studio Code. Nvim I like to use it for quick browsing, code editing. For something more complex I would use Visual Studio Code Editor.

Visual Studio Code vs Nvim advantages:

What I really like from Visual Studio Code is that I can jump to system libraries and third parties source code definition. I can do similar with ctags or rtags in Neovim but in Visual Studio Code is out of the box.

Extensions are more friendly in Visual Studio Code than the ones for the Coc plugin in Neovim. Setup is harder in Neovim.

Debugging is also out of the box with Visual Studio Code. When using only vim I’m used to use gdb.

C++ debugging with gdb. mongocxx::uri

How it goes with Visual Studio Code integrated debugger:

C++ debuging with gdb, but inside Visual Studio Code!

Setting up libraries and IDE for third party libraries in C++ is not easy. That is the C++ world! For the libraries setup

sudo dnf install mongo-c-driver-devel
sudo dnf install mongo-cxx-driver-bsoncxx-devel
sudo dnf install boost-devel
sudo dnf install mongo-cxx-driver-devel

To compile:

g++ -g --std=c++17 mongodb_main.cpp `pkg-config libmongoc-1.0 --cflags` `pkg-config libmongocxx` --cflags --libs -o mongodb_mai

For the Neovim setup, Install COC and coc clang extension. Install clangd Language Server of course as well.

For Neovim I had to create compile_commands.json file.


For Visual Studio I had to create c_cpp_properties.json:



Leave a Reply

Your email address will not be published. Required fields are marked *