How to fix error: recompile with -fPIC

I am using cmake to build my project in linux.

An error is reported:

build] [  0%] Automatic MOC for target SUTKBaseCore
[build] [  0%] Built target SUTKBaseCore_autogen
[build] [ 16%] Linking CXX shared library
[build] /bin/ld: /home/qiang_zhang/Desktop/Thirdparty/FMT9.1.0/install/lib/libfmt.a( relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC

I have tried to add add_compile_options(-fPIC) and target_compile_options(SUTKBaseCore PRIVATE -fPIC) in my CMakeLists.txt, but it do not work.

How can I fix this error? Any suggestion is appreciated~~~

My environment is:

gcc 8.4.0 x86_64-linux-gun

You need to compile fmt with -fPIC. You can pass -DCMAKE_POSITION_INDEPENDENT_CODE=ON to fmt configure to make this happen.

1 Like