I am trying to setup opencv c++ with the help of cmake tool, and here are things that I have done.but I got some error,
my CMakeLists.txt is as follow,
cmake_minimum_required(VERSION 3.0.0)
project(edge VERSION 0.1.0)
include(CTest)
enable_testing()
# these two line are added by me
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(edge main.cpp)
# this one line is added by me
target_link_libraries(edge ${OPENCV_LIBS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
here is PATH, PATH
my vscode config c_cpp_properties.json is as follows,
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}",
"C:\\opencv\\build\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:\\mingw64\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "${default}",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
and my main.cpp is just for test (I'll write code later).
#include <iostream>
#include <opencv2/opencv.hpp>
int main(int, char**) {
cv::Mat src;
std::cout << "Hello, world!\n";
return 0;
}
and I got some chunky lines on my terminal, here
[main] Building folder: edge edge
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build f:/edge/build --config Debug --target edge -j 4 --
[build] [ 50%] [32m[1mLinking CXX executable edge.exe[0m
[build] CMakeFiles\edge.dir/objects.a(main.cpp.obj): In function `main':
[build] F:/edge/main.cpp:5: undefined reference to `cv::Mat::Mat()'
[build] F:/edge/main.cpp:5: undefined reference to `cv::Mat::~Mat()'
[build] F:/edge/main.cpp:5: undefined reference to `cv::Mat::~Mat()'
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make.exe[3]: *** [CMakeFiles\edge.dir\build.make:99: edge.exe] Error 1
[build] mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:838: CMakeFiles/edge.dir/all] Error 2
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:845: CMakeFiles/edge.dir/rule] Error 2
[build] mingw32-make.exe: *** [Makefile:517: edge] Error 2
[build] Build finished with exit code 2
Actually I want to know why these error ? how to fix. (I guess some linking issue or something else.)
Note -: currently I am in windows environment. (please consider this).