简体   繁体   中英

Cannot find opencv in visual code studio (for c++ in ubuntu)

I am trying to write a code in C++ using Opencv in visual code studio (ubuntu).

I compiled opencv following the next tutorial: http://www.codebind.com/cpp-tutorial/install-opencv-ubuntu-cpp/

And I would like to use Visual code studio, but I am not able to make it work.

My cpp code is the following one:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

// using namespace cv;
// using namespace std;

int main(int argc, char const *argv[])
 {
std::cout << "Hello World\n";

cv::Mat image;
image = cv::imread("image.jpg");   // Read the file
// namedWindow("show image",WINDOW_AUTOSIZE);
//imshow("show image", image);


std::cin.get();
return 0;
}

My c_cpp_propierties.json file is the next one:

{
"configurations": [
    {
        "name": "Linux",
        "browse": {
            "path": [
                "/opt/opencv/include/opencv",
                "${workspaceFolder}"
            ],
            "limitSymbolsToIncludedHeaders": true
        },
        "includePath": [
            "/opt/opencv/include/opencv",
            "${workspaceFolder}/**"
        ],
        "defines": [],
        "compilerPath": "/usr/bin/gcc",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x64"
    }
  ],
  "version": 4
}

And the task json is

{
    "version": "2.0.0",
    "tasks": [
    {
        "label": "build hello world",
        "type": "shell",
        "command": "g++",
        "args": [
            "-g", "canny.cpp"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]
}

When I compile the code I receive the following output:

Executing task: g++ -g canny.cpp <

/tmp/cc01zEdA.o: In function main': /home/beaa/Estudio/CPP/basicOpenCV/canny.cpp:13: undefined reference to cv::imread(cv::String const&, int)' /tmp/cc01zEdA.o: In function cv::String::String(char const*)': /usr/local/include/opencv2/core/cvstd.hpp:597: undefined reference to cv::String::allocate(unsigned long)' /tmp/cc01zEdA.o: In function cv::String::~String()': /usr/local/include/opencv2/core/cvstd.hpp:643: undefined reference to cv::String::deallocate()' /tmp/cc01zEdA.o: In function cv::Mat::~Mat()': /usr/local/include/opencv2/core/mat.inl.hpp:682: undefined reference to cv::fastFree(void*)' /tmp/cc01zEdA.o: In function cv::Mat::release()': /usr/local/include/opencv2/core/mat.inl.hpp:794: undefined reference to cv::Mat::deallocate()' /tmp/cc01zEdA.o: In function cv::Mat::operator=(cv::Mat&&)': /usr/local/include/opencv2/core/mat.inl.hpp:1357: undefined reference to cv::fastFree(void*)' collect2: error: ld returned 1 exit status El proceso del terminal finalizó con el código de sa lida: 1

As you can see, I use gcc as compiler.

I suppose that the opencv route is not found, but I have tried to fix it and I am not able.

Thanks in advance

Compiling an opencv cpp code in ubuntu is actually pretty simple. You can use this link to do so . http://answers.opencv.org/question/25642/how-to-compile-basic-opencv-program-in-c-in-ubuntu/

You need to download and extract opencv files to a location, write a cpp code and while running from commandline just give opencv include and lib paths.

You can use the described procedure if using visual studio in ubuntu is not mandatory in your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM