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