I'm trying to compile my C++ program which uses opencv, here is my code:
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main()
{
cout << "Hello world!\n";
Mat image = cv::imread(R"(1596254171-image.jpg)");
return 0;
}
It's a quite simple code. And here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
project(testbed_ VERSION 1.0)
set(EXECUTABLE_OUTPUT_PATH ../bin)
set(ext_third_party_dir /home/mtd/third_party)
set(opencv_lib_dir /home/mtd/third_party/opencv_4.2.0/lib/)
set(opencv_lib ${opencv_lib_dir}/libopencv_imgcodecs.so
${opencv_lib_dir}/libopencv_imgproc.so.4.2
${opencv_lib_dir}/libopencv_core.so)
add_executable(testbed_ ../main.cpp)
target_include_directories(testbed_ PUBLIC ${ext_third_party_dir}/include)
target_link_libraries(testbed_ PUBLIC ${opencv_lib} )
The compilation operation is everything OK, but when I executed my testbed_, I got the error:
error while loading shared libraries: libopencv_imgproc.so.4.2: cannot open shared object file: No such file or directory
I wonder why I've already specified the link path but the linker still cannot fint the imgproc lib, and why core.so can be found but imgproc.so not ?