Deftness Deftness - 11 months ago 193
C++ Question

Visual Studio Code: C++ include path

I'm currently using which is great as a nice little tool for accessing member functions.

I am however having one issue with a project I am importing. While the above clang feature works, I am having particular problem with using include directories. My project structure is as follows:

|- src/
|- main.cpp
|- include/
|- MyHelper.h
|- CMakeLists.txt

Is there a way to configure my include directories in Visual Studio Code such that in
I can just do:
#include "MyHelper.h"
instead of
#include "include/MyHelper.h"?

In the editor, it highlights my include statement saying it's unable to find the file. While the editor is not a big deal (my project compiles), the subsequent issue is the vscode-clang plugin does not work because it does not see the file.

Perhaps even have it use the config from my CMakeLists.txt in the editor for necessary includes?


Answer Source

Okay, this was foolish, but in the event someone uses Visual Studio Code and does not have a trivial project. These instructions are assuming you're using clang compiler:

  1. Open your project directory
  2. Open .vscode/settings.json
  3. Configure the line below inside of the JSON object:

    // Compiler options for C++ (e.g. ['-std=c++11'])
    "clang.cxxflags": [
        "-I/path/to/my/include/directory" // header files