Failure to link opencv4tegra package into another .so object

I’m getting a weird link error when I try to link opencv4tegra package against another shared library I’m building when I’m trying to link as “whole archive”.

$ clang++  -shared -Wl,--export-dynamic -Wl,-soname,libmything.so.1.0 $OBJECTS -Wl,--whole-archive -L$OUT -L/usr/lib    -lsnmp -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lopencv_esm_panorama -lopencv_facedetect -lopencv_imuvstab -lopencv_tegra -lopencv_vstab -lcufft -lnpps -lnppi -lnppc -lcudart -lrt -lpthread -lm -ldl -ldl -lpthread -lrt -lm -Wl,--no-whole-archive -o $SO
/usr/bin/ld: /usr/lib/libopencv_ts.a(gpu_test.cpp.o): relocation R_ARM_THM_MOVW_ABS_NC against `__pthread_key_create' can not be used when making a shared object; recompile with -fPIC
/usr/lib/libopencv_ts.a(gpu_test.cpp.o): error adding symbols: Bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)

One solution, though not optimal, is to just remove opencv_ts as that is the problem library. However, I’m generating this list from:

$ pkg-config --libs opencv

Which automatically generates this list of libs. I can use a filter-out rule in make, but this doesn’t really solve the problem in the long run.

Hi emrainey,

Could your use g++ compiler and see whether this error still exists?

Thank you.

G++ 4.8.2 can’t even compile this code without failing, for unrelated DWARF symbol issues. I’ll have to check later.

Hi emrainey,

Could you share the sample code for this compiling error?
Thank you.