What is correct include path for (C++) opencv in Ubuntu?

Hi,

I have a C++ OpenCV project that uses Visual Studio Code with a CMake file.
It runs on a Ubuntu OS.

Now I switched from cmake file to configuration using json files.
In the cmake file I did not have to add the include path for OpenCV. But now it can not find the opencv hpp files so I have to include the include path in .vscode/c_cpp_properties.json

But when including
/usr/local/include/opencv4
or
/usr/local/include/opencv4/
or
/usr/local/include/opencv4/**

it still can not find it.
While I checked and the include files are present there.

Any idea what could be wrong?

There is an example how to use cmake and opencv for your project here

Maybe I was not clear enough:

But the CMake file is not the problem. I had a project running using CMake.
But I had to switch to the json file way of configuration (Visual Studio Code).

Now I need the include path for OpenCV. And I can not find out what this path should be.

CMake will generate project for visual studio. Get started with CMake Tools on Linux

CMake can also generate build files for Ninja, or regular old Makefiles.

VSCode != Visual Studio. VSCode doesn’t just run on Windows.

I’m confused.
I use Visual Studio Code (VSCode) on Ubuntu for my C++ OpenCV project.

I use the .json files for cofiguration (tasks.json, launch.json and c_cpp_properties.json).

How do I now tell the compiler which (OpenCV) include files to use? And which libraries to use for linking?
I would like to do that without using CMake files. Is that possible? If so, how?

no. you have to use cmake to generate any build files (Makefile, Ninja, …)

try

cmake -G “Unix Makefiles” .

and import your makefile in VS

I would like to only use the json files. No make files. This because it is easier for me to understand. But also because when I added a CMake file the launch.json didn’t function correct anymore. I need to run the debugger in sudo mode and that can be done with the correct lines in the launch.json file. But with the CMake file added, it did not work anymore.

I assumed the include files should be listed in the c_cpp_properties.json file. But I found out that this is only for the Intelisense functionality.
The include paths and library paths need to be added to the arguments for the compiler in the tasks.json file.

I just download vscode. I run cmake outside or inside vscode. In vscode I open build folder and I can select run debug in vscode

unfortunately we can’t help you with your niche desires.

this is the OpenCV forum, not the VSCode forum.

Yes, I had CMake working too in combination with VSCode. But in combination with a launch.json file it did not work for me. I need the launch.json to make the debugger run in sudo mode.

Therefore I want to use the tasks.json to make the project.
Anyway, my question was how to define the include directory paths and library paths in the json files.

So my tasks.json looks like this:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.cpp",
                "-I/usr/local/include/opencv4",
                "-o",
                "${fileDirname}/myProg"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

I checked that my opencv2 includes are at /usr/local/include/opencv4

But it still does not work. The compiler does not find the include files it needs.

Ok
Thanks anyway.
I will try to find a forum that can help me.

that “tasks.json” thing is a thing specific to VSCode and there’s nothing special about OpenCV in relation to this “tasks.json”