I'm just trying compile this opencv simple code with CMake
int main(int argc, char** argv )
{
string path = "/imgs/lenna.png";
Mat img = imread(path);
imshow("Lenna", img);
namedWindow("Lenna", WINDOW_AUTOSIZE);
waitKey(0);
return 0;
}
but this always return me this error
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --build c:/Users/CADSE/Desktop/Programs/usingcvtest/build --config Debug --target opencvtest -j 6 --
[build] [ 50%] Building CXX object CMakeFiles/opencvtest.dir/main.cpp.obj
[build] [100%] Linking CXX executable opencvtest.exe
[build] CMakeFiles\opencvtest.dir/objects.a(main.cpp.obj): In function `main':
[build] C:/Users/CADSE/Desktop/Programs/usingcvtest/main.cpp:13: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
[build] C:/Users/CADSE/Desktop/Programs/usingcvtest/main.cpp:14: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
[build] C:/Users/CADSE/Desktop/Programs/usingcvtest/main.cpp:15: undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
[build] C:/Users/CADSE/Desktop/Programs/usingcvtest/main.cpp:17: undefined reference to `cv::waitKey(int)'
[build] C:/Users/CADSE/Desktop/Programs/usingcvtest/main.cpp:13: undefined reference to `cv::Mat::~Mat()'
[build] C:/Users/CADSE/Desktop/Programs/usingcvtest/main.cpp:13: undefined reference to `cv::Mat::~Mat()'
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make.exe[3]: *** [CMakeFiles\opencvtest.dir\build.make:115: opencvtest.exe] Error 1
[build] mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:838: CMakeFiles/opencvtest.dir/all] Error 2
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:845: CMakeFiles/opencvtest.dir/rule] Error 2
[build] mingw32-make.exe: *** [Makefile:517: opencvtest] Error 2
[build] Build finished with exit code 2
[main] Failed to prepare executable target with name 'undefined'
and I don't know why cause I already searched in the internet but I found nothing, here my CMakeList
cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)
include(CTest)
enable_testing()
SET("OpenCV_DIR" "C:\\opencv\\build\\x64\\vc14\\lib")
find_package( OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(opencvtest main.cpp)
target_link_libraries( opencvtest ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)