-1

i know this question has been asked before but i can't understand their explanation. i am completely new to coding , help if you can.

here is my file image: here is my file image

here is my task jason files:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "`pkg-config",
                "--cflags",
                "--libs",
                "opencv4`"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/bin/g++"
        }
    ]
}

and here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(ObjectDetection)

set(OpenCV_DIR C:/Users/prana/OneDrive/Desktop/last_attempt/opencv)
find_package(OpenCV REQUIRED)

add_executable(${PROJECT_NAME} src/Main.cpp)

target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
6
  • Are you using the CMakeTools extension? To me it does not look like the tasks.json was generated by cmake. Also are you using WSL since the /usr/bin/g++ is not a windows path? Commented Oct 23, 2023 at 17:02
  • I do not know what a tasks JSON is, but pkg-config --cflags should give you include directories. However, I notice the argument is opencv4, not opencv2. Is this the correct name of the package? Now I do not know why CMake and this tasks JSON are used simultaneously, but the way to add an include directory in CMake is target_include_directories(${PROJECT_NAME} PRIVATE path-to-your-include-directory). Furthermore, since, according to the error message, it is looking for opencv2/opencv.hpp, you have to specify the path up till, but not including the opencv2 directory. Commented Oct 23, 2023 at 17:13
  • @larry i was looking another solution of the same they said that their programme worked when they changed their task.json to this so i changed it as well Commented Oct 23, 2023 at 17:31
  • Your tasks.json looks like its from a POSIX system like linux. Commented Oct 23, 2023 at 17:33
  • Please copy and paste the exact text into your question showing your actual build commands executed when CMake was used. Your tasks.json has nothing to do with CMake. Commented Oct 23, 2023 at 17:34

2 Answers 2

0

The error:

The error you describe is a result of executing a line of code attempting to access the file opencv2/opencv.hpp. Since this extension is hpp, it is a header file: simply put, header files help different files within the source code all share the same core variables. The error associated with failure to access a header file likely occurs in the preamble of one of the opencv2 source files.

In general, when implementing downloaded source code, this is the result of failure to configure the file structure in the expected way (assuming you downloaded everything). Make sure to check that you have both OpenCV_contrib AS WELL AS OpenCV.

Solution:

Make sure that your '/build' path is included.

Since this question is already answered in a very thorough manner (by Faisal_L), for a particular solution I direct you to follow the instructions they laid out below.

https://stackoverflow.com/a/73186585/21977063

Sign up to request clarification or add additional context in comments.

Comments

0

Try adding /build to change

set(OpenCV_DIR C:/Users/prana/OneDrive/Desktop/last_attempt/opencv)

to

set(OpenCV_DIR C:/Users/prana/OneDrive/Desktop/last_attempt/opencv/build)

1 Comment

it was this before but i changed it when i looked at another solution on same querry. in short yes i have tried it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.