Dave
Dave

Reputation: 57

How to fix "No such file or directory..." error due to C++ includePath

I am trying to include multiple hpp files in my code, however the include path option in my c_cpp_properties.json doesn't seem to be working correctly. I keep getting the "No such file or directory..." even though the correct files are there.

I have added the path to the includePath section of the c_cpp_properties.json file and it still isnt finding the files.

Include Part of Main File:

#include <iostream>
#include<conio.h>
#include <D:\OpenCV\opencv\build\include\opencv2\core\core.hpp>
#include <D:\OpenCV\opencv\build\include\opencv2\highgui.hpp>
#include <D:\OpenCV\opencv\build\include\opencv2\imgproc\imgproc.hpp>

c_cpp_properties.json File:

    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:/OpenCV/opencv/build/include",
                "D:/OpenCV/opencv/sources/modules/core/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}```

The file should run, but this error is causing it not to.

Upvotes: 0

Views: 1764

Answers (1)

Ted Lyngmo
Ted Lyngmo

Reputation: 117643

If c_cpp_properties.json contains properties used when compiling, your #includes should probably look like this:

#include <iostream>
#include <conio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

The single backslashes you have in your #includes are most probably interpreted as the start of escape sequences which will not result in correct paths.

Upvotes: 1

Related Questions