Fisteshak
Fisteshak

Reputation: 67

How can I tell VS Code which of my installed standard library headers to use?

When I use VS code, it takes hints from MSVC's standard library headers (they also can be seen by pressing "go to definition"), which barely has any documentation comments or hints. However, GCC's standard library header source code has much better documentation comments. I didn't find any settings or tasks that change this. Is there a way to change it?

Upvotes: 2

Views: 938

Answers (1)

starball
starball

Reputation: 50315

If you're not using CMake...

Write a c_cpp_properties.json file.

Quoting from the docs for the compilerPath property:

The extension will query the compiler to determine the system include paths and default defines to use for IntelliSense.

Putting "compilerPath": "" (empty string) will skip querying a compiler. This is useful if a specified compiler doesn't support the arguments that are used for the query, as the extension will default back to any compiler it can find (like Visual C). Leaving out the compilerPath property does not skip the query.

Quoting the docs for the includePath property:

If on Windows with Visual Studio installed, or if a compiler is specified in the compilerPath setting, it is not necessary to list the system include paths in this list.

Note also that you can specify system include paths as a setting, C_Cpp.default.systemIncludePath, with related docs here and here.


VS Code's various setup guides for C++ on different platforms / platform toolchain setups, they each have a section on how to configure the c_cpp_properties.json file for that toolchain+plaform combination. You'll find it really helpful, because each of those sections shows a code snippet of the basic setup.

Here are links to all the current toolchain+platform sub-pages at the relevant section (I'll inline the snippets for the Windows GCC ones just for you, but please do also check out those pages for up-to-date versions):

If you are using CMake...

Use the vscode.cmake-tools extension, and either instruct the extension to scan for kits that can be found on your system, or set up (and tell VS Code to use) a CMake Presets file with where to find the compilers. Compilers usually know by default where their standard library headers are (if they come with them, which packages for compilers usually do).

Upvotes: 1

Related Questions