1 | initial version |
Ok after searching everywhere. I finally did it. I am using docker containers as my working environment. I am using OpenCV 4.0.1 and Ubuntu 18.04. My docker file can be found at DockerFile. (The docker image is still built dynamically just follow the steps below to enable static build.)
There are basically two things to do to static compile successfully.
-D BUILD_SHARED_LIBS=OFF
AND
-D OPENCV_GENERATE_PKGCONFIG=YES
The second option will save you the hassle of manually linking all libraries during compilation. It is very critical. And to compile I just used the typical:
g++ main.cpp -o test `pkg-config --cflags --libs --static opencv4`
Just remember to set the $PKG_CONFIG_PATH to where the opencv4.pc is located.I set mine via:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
You can check it by: echo $PKG_CONFIG_PATH
I hope this helps anyone struggling to do this!