# How to fix error: recompile with -fPIC

**URL:** https://discourse.cmake.org/t/how-to-fix-error-recompile-with-fpic/7626
**Category:** Usage
**Created:** [March 8, 2023, 10:05am UTC](https://discourse.cmake.org/t/how-to-fix-error-recompile-with-fpic/7626 "2023-03-08T10:05:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [March 8, 2023, 10:05am UTC](https://discourse.cmake.org/t/how-to-fix-error-recompile-with-fpic/7626/1 "2023-03-08T10:05:47Z")

</div>

I am using `cmake` to build my project in linux.

An error is reported:

```auto
build] [0%] Automatic MOC for target SUTKBaseCore
[build] [0%] Built target SUTKBaseCore_autogen
[build] [16%] Linking CXX shared library libSUTKBaseCored.so
[build] /bin/ld: /home/qiang_zhang/Desktop/Thirdparty/FMT9.1.0/install/lib/libfmt.a(format.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

```

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:

```auto
linux
gcc 8.4.0 x86_64-linux-gun

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 11, 2023, 12:57am UTC](https://discourse.cmake.org/t/how-to-fix-error-recompile-with-fpic/7626/2 "2023-03-11T00:57:24Z")

</div>

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