I built OpenCV with the following on ubuntu:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_SHARED_LIBS=OFF \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D BUILD_JAVA=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_ZLIB=ON \
-D BUILD_TIFF=ON \
-D BUILD_JASPER=ON \
-D BUILD_JPEG=ON \
-D BUILD_PNG=ON \
-D BUILD_OPENEXR=ON \
-D BUILD_WEBP=ON \
-D BUILD_EXAMPLES=OFF ..
And naively assumed cmake would handle my test program's link plan automatically. However, to get my auto-porting script to work I was forced to try to recover the library build variables directly from the cmake output to reconstruct the shared and static dependencies I needed.
externalLibs=$(/bin/opencv_version -v | grep ' Extra dependencies:' | cut -d':' -f2 | sed -r 's/( )+/ -l/g')
staticLibs=$(cat OpenCVModules.cmake | grep 'IMPORTED_LOCATION_RELEASE' | sed -r 's/IMPORTED_LOCATION_RELEASE//g' | sed -rz 's/[" \r\n]+/ /g' )
headers=$(cat OpenCVConfig.cmake | grep 'set(OpenCV_INCLUDE_DIRS ' | sed -r 's/set\(OpenCV_INCLUDE_DIRS//g' | sed -r 's/( ")+/ -I/g' | sed -r 's/["\)]+//g' )
The issues I have encountered (screens of missing refs like "undefined reference to `cv::softdouble::operator/") seem rather dated: Undefined references in static OpenCV libraries Undefined references in static OpenCV libraries And the solutions others have used seem use-case specific: https://forum.qt.io/topic/51543/solved-cannot-link-libs-statically Why does the order in which libraries are linked sometimes cause errors in GCC?
Is there a better way to import and build a program against a specific set of static opencv libraries within cmake without installing the architecture specific build versions to handle the cmake magic?
Or do people actually manually statically link the 20 some odd libs ;-)
ar cr libopencv_core.a myappobj.o
Any insights would be appreciated, as the cmake files were getting complex given I also intend to statically link wxWidgets into the same program. I have made a little progress by reverse engineering the auto-generated cmake link.txt files in the opencv testing application's build tree. However, there has to be a better method of doing this without reverting to shared libs that are not always cross-platform friendly... ;-)