0

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 tocv::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 tocv::String::allocate(unsigned long)' /tmp/cc01zEdA.o: In function cv::String::~String()': /usr/local/include/opencv2/core/cvstd.hpp:643: undefined reference tocv::String::deallocate()' /tmp/cc01zEdA.o: In function cv::Mat::~Mat()': /usr/local/include/opencv2/core/mat.inl.hpp:682: undefined reference tocv::fastFree(void*)' /tmp/cc01zEdA.o: In function cv::Mat::release()': /usr/local/include/opencv2/core/mat.inl.hpp:794: undefined reference tocv::Mat::deallocate()' /tmp/cc01zEdA.o: In function cv::Mat::operator=(cv::Mat&&)': /usr/local/include/opencv2/core/mat.inl.hpp:1357: undefined reference tocv::fastFree(void*)' collect2: error: ld returned 1 exit status El proceso del terminal finalizó con el código de salida: 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

1 Answer 1

0

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.

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

Comments

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.