How to get C++ autocomplete suggestions in VScode
Tags: vscode
Published: 2021-05-31 08:12:25

VScode is a terrific code editor. It has everything a developer could ask for — Git integration, syntax coloring for different languages, an integrated terminal — it even lets you run and debug programs from within the editor. It’s a full-fledged IDE that few can rival in features.

But with all its star-studded capabilities, there was one missing feature that particularly irked me; I was using Windows 8 (don’t ask), and I wanted VScode to show me class and function definitions for external libraries in my C++ code so that I could avoid googling them and interrupting my burst of productivity.

##Initial roadblocks

The major setback was I could not use the services of **[vcpkg](https://en.wikipedia.org/wiki/Vcpkg)** because it does not run on Windows 8. So I had to think of an alternative solution.

Since the C/C++ plugin had a setting for configuring include paths, to kick in its own Intellisense, all I had to do was download the header files for stdc++, Boost, libc, and a few others, and Intellisense would scan those for its suggestions instead of using headers provided by vcpkg.

The next problem was where I would get the header files from. Downloading them from each project's website and compiling them by source was not an option due to the Windows OS. But then an idea hit me.

## Just use Linux binary packages

Since I was writing programs for the CentOS distribution, why don’t I download the development packages of each library I need, and extract their header files somewhere and add them into the Intellisense include path?

I found a site called https://pkgs.org, which contains the packages for all distributions available to download. It also stores packages for each distribution version. Most importantly, it lets you search for packages by filenames of their contents. In my case, I needed the versions of the libraries shipped in CentOS 7.

The last problem was related to how Intellisense recursively scans header files. If any nested header files from others are not found, then the Intellisense capability will not work, and you won’t get autocomplete. As a result, I not only needed to download standard C++ headers and Boost headers, I also had to download the headers from GCC, MinGW, and even the Linux kernel, because I was using the CentOS 7 version of these libraries.

Also, since the Intellisense scan aborts at the first header file it fails to find, and there are dozens of nested header files to process, it took a minute or two between scans before I could get diagnostic messages from missing header files. This caused the whole process of finding all the dependency packages to take about 20 minutes.

## Package list for CentOS C++/Boost

To save you all the time that I lost from looking for the specific nested development packages to use, I have compiled a list of the package names for Red Hat, Fedora & CentOS that provide all the C++ and Boost header files for the Intellisense scan to successfully complete. These packages have similar names on Debian and Ubuntu, most ending with “-dev” instead of “-devel”.

- boost-devel
- libstdc++-devel
- glibc-headers
- gcc
- kernel-headers
- mingw64-headers

## Extracting folders, and editing settings.json

After the packages are downloaded, the include folder must be extracted from them. For this, I used [7-Zip](https://www.7-zip.org/), which can extract both .deb packages and .rpm packages along with the nested .cpio archive in every RPM package.

I recommend that each package is extracted into a separate folder to avoid file name clashing on Windows, where files in one package overwrite files in another package. The only limitation of this approach was that files that had the same name but in different cases also overwrite each other on Windows, but I only had this problem with the kernel-headers package. As an indirect dependency, it did not affect Intellisense’s ability to scan the header file hierarchy successfully.

Finally, I had to add the extracted folders into the include path for Intellisense. To do that, the `C_Cpp.default.systemIncludePath` key needed to be added to the `settings.json` configuration file. Its value is an array of string paths to include folders. Fill them in with the paths to the folder you extracted.

---

That’s it! Enjoy your C++ autocomplete in VScode.

*Cover image licensed under Creative Commons*