Visual Studio Code - Include Path Problems Header Files C++ (MinGW)

Viewed 2187

I am pretty new to programm in C++ so please don't judge my problems with setting up my "Visual Studio Code" environment. I am trying to use the blaze math packages to solve quadratic programming problems. With the MinGW GCC I can compile the testfiles of blaze successfully via cmd and thus I want to use the GCC for VS Code.

OS: Windows 10.0.19041

GCC: gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 7.3.0 || (cmd: gcc --version)

VS Code Extensions: C/C++ 0.27.1

Firstly I went through the VS Code tutorial for MinGW: https://code.visualstudio.com/docs/cpp/config-mingw

This worked fine so I can easily compile my helloworld.cpp. The resulting tasks.json file looks like this tasks.json.

As my package manager (for blaze or other packages) i use the vspkg-git: https://docs.microsoft.com/en-us/cpp/build/vcpkg?view=msvc-160 Thus I am programming on Windows I can't use the "integrate" command to add the path to the includepath. So I have to do this manually.

My packages are in the folder with the absolute path

C:\Users\Johannes\Desktop\Masterthesis\vcpkg\vcpkg\packages

So I added the path on the "c_cpp_propertier.json"-file

{
"configurations": [
    {
        "name": "GCC",
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "gcc-x64",
        "includePath": [
            "${workspaceFolder}",
            "C:/Users/Johannes/Desktop/Masterthesis/vcpkg/vcpkg/packages/**"
        ],
        "compilerPath": "C:/Program Files/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/bin/g++.exe",
        "browse": {
            "path": []
        }
    }
],
"version": 4
}

In the folder are several packages therefor I added the "/**" at the end of the path to enable the recursive search for header files.

My 'helloworld.cpp' file looks like this

#include <iostream>
#include <vector>
#include <string>
//#include <blaze/Math.h>

using namespace std;

int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the 
C++ extension!"};

for (const string& word : msg)
{
    cout << word << " ";
}
cout << endl;
}

My problem is that when I try to include a header-file from this path for example Math.h Visual Studio throws an Error

blaze/Math.h: No such file or directory

But when I right-click on the include and click "Go to Definition" VS Code opens the file. Optionbar and the opened file.

The Log-Diagnostics gives that information.

I guess someone that has experience with MinGW and additional packages in VS Code will solve that problem very simple, but I have read nearly every thread about those problems and didn't find anything matching mine.

1 Answers

Okay, i got the answere. The include path of the "c_cpp_properties.json" file is only for IntelliSense. This means that Visual Studio Code will find this packages and IntelliSense will suggest you the available headers from the pathes. This does not mean that the compiler can find these pathes. Therefor you have to add the pathes to the "tasks.json" file. As you can see above in the photo of the "tasks.json" file, there is a field called "args" which means "arguments". Those are the compiler arguments. You have to add the Path there too in Format "-I","C:/PathYouWishToAdd". This works fine!!

changed tasks.json file

Related