I built opencv from source and wrote basic code with C++. I want to compile it but don't know how can I do it. I researched about it and found different solutions such as pkg-config and cmake or makefile. But I want to learn how can I compile it manually. So I want to link opencv with C++.
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
Mat image = imread("image.jpg");
namedWindow("Image", WINDOW_NORMAL);
imshow("Image", image);
waitKey(0);
destroyWindow("Image");
return 0;
}
I tried g++ -o program DisplayImage.cpp -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc
command. But it was unsuccessful. I received error like that:
/usr/bin/ld: /tmp/ccAYFp5J.o: in function `main':
DisplayImage.cpp:(.text+0x65): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
collect2: error: ld returned 1 exit status
How can I compile the code with g++ compiler and how can I link opencv?