Undefined reference to g_Saturate8u

I’ve written a static library that uses OpenCV but now that I’m trying to port it as a single binary I’m running into some problems. I’ve built opencv_world and tried to combine them using AR. Now creating some sandbox application and linking to my library I’m getting several linker errors, most notably to cv::g_8x32fTab and cv::g_Saturate8u and cv::ParallelLoopBody, any ideas on how to fix this?

os / compiler / opencv version ?

how do you link that ? (please show !)

did you build static opencv libs as well ?
note, for static libs, you have to list them ordered by dependency, so since imgproc depends on core, core has to go after that.

you’ll also need to explicitly list all 3rdparty libs, like -lz -ljpeg -lpng, etc at the end of that list

1 Like

I apologize if you get multiple replies but for some strange reason whenever I edit a reply it just disappears so:

I built OpenCV with

cmake \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_opencv_apps=ON \
-D BUILD_PACKAGE=ON \
-D BUILD_opencv_world=ON \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_OPENCV_highgui=ON \
-D BUILD_opencv_imgproc=ON \
-D BUILD_PROTOBUF=ON \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_opencv_calib3d=ON \
-D BUILD_opencv_core=ON \
-D BUILD_opencv_dnn=ON \
-D BUILD_opencv_features2d=ON \
-D BUILD_opencv_flann=ON \
-D BUILD_opencv_gapi=ON \
-D BUILD_opencv_highgui=ON \
-D BUILD_opencv_imgcodecs=ON \
-D BUILD_opencv_imgproc=ON \
-D BUILD_opencv_ml=ON \
-D BUILD_opencv_stitching=ON \
-D BUILD_opencv_video=ON \
-D BUILD_opencv_videoio=ON \
-D BUILD_IPP_IW=ON \
-D BUILD_JPEG=ON \
-D BUILD_OPENJPEG=ON \
-D BUILD_ZLIB=ON \
-D BUILD_TESTS=OFF \
-D BUILD_ITT=ON \
-D BUILD_JASPER=ON \
-D BUILD_OPENEXR=ON \
-D BUILD_OPENJPEG=ON \
-D BUILD_PNG=ON \
-D BUILD_TBB=ON \
-D BUILD_WITH_DYNAMIC_IPP=OFF \
-D BUILD_WITH_STATIC_CRT=ON
-D OPENCV_ENABLE_NONFREE=ON

Then I combine the libraries with:

ar -x libzlib.a
ar -x libittnotify.a
ar -x liblibpng.a
ar -x liblibprotobuf.a
ar -x libade.a
ar -x libIlmImf.a
ar -x liblibjpeg-turbo.a
ar -x libippicv.a
ar -x liblibopenjp2.a
ar -x libopencv_world.a
ar -x libquirc.a
ar -x libippiw.a

ar -qc libcombined.a *.o

Then statically linking libcombined.a to a sandbox project i get the aforementioned linker errors.

apologies for our over-eager spam bot (it hates fast tying ppl …)

i’ve never used the ‘world’ lib, however, the missing functions are all from the core module

Yes that’s what surprised me as well, good news however! It turns out you were right originally, the order was the issue at hand, and since I was wildcarding it (through *.o) it messed it up quite a bit.

The solution I went with was to just use ar -M <merge.mri with the file being:

create libcombined.a
addlib lib1.a
addlib lib2.a
addlib ...
save
end

and it worked out flawless.

Much appreciated!

2 Likes