/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC

Hi!

Following the indications found here: OpenCV: OpenCV configuration options reference I’m trying to compile, build and install OpenCV 4.8 in Ubuntu 23.10

I compiled:

raphy@raohy:~/builddir-opencv$ cmake CXXFLAGS="$CXXFLAGS -fPIC" 
-DOPENCV_FORCE_VTK=TRUE -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-
4.x/modules ../opencv-4.x

without any errors

But, in building phase, I get this error:

[ 94%] Linking CXX shared library ../../lib/libopencv_sfm.so
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags_completions.cc.o): warning: relocation against `_ZN3fLS25FLAGS_tab_completion_wordB5cxx11E' in read-only section `.text.startup'
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
gmake[2]: *** [modules/sfm/CMakeFiles/opencv_sfm.dir/build.make:242: lib/libopencv_sfm.so.4.9.0] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:7756: modules/sfm/CMakeFiles/opencv_sfm.dir/all] Error 2

How to make it work?

do you need sfm? if not, disable it and move on. browse values listed by cmake-gui to find the option.

crosspost: