Ask Your Question

Revision history [back]

How to generate/install OpenCV for static linking?

Hi, I am trying to build a program that can used on other machines without opencv. I have a machine installed using the usual process of building from source. From what I read I need to turn the BUILD_SHARED_LIBS = OFF option. After this I do not know how to proceed. I can see that some files are in the usr/local/include and usr/local/libs. Is this the right way to generate static libs? Also how do I compile the static libs for my program? Thank you.

How to generate/install OpenCV for static linking?

Hi, I am trying to build a program that can used on other machines without opencv. I have a machine installed using the usual process of building from source. From what I read I need to turn the BUILD_SHARED_LIBS = OFF option. After this I do not know how to proceed. I can see that some files are in the usr/local/include and usr/local/libs. Is this the right way to generate static libs? Also how do I compile the static libs for my program? Thank you.

EDIT I tried the following to compile.

g++ main.cpp -I /usr/local/include/opencv4 -L/usr/local/lib -lopencv_dnn -lopencv_features2d -lopencv_calib3d -lopencv_flann -lopencv_gapi -lopencv_objdetect -lopencv_ml -lopencv_photo -lopencv_video -lopencv_videoio -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_stitching  -L/lib/x86_64-linux-gnu -libz -lpng -ljpeg -o binary

and

g++ -I/usr/local/include/opencv4 -I/usr/local/include/opencv4 -L/usr/local/lib/ -g -o binary  main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching

Only to get a bunch of undefined reference errors.