2

Is there any harm in always compiling with -fPIC even if I might not intend to link the resulting relocatable object files into a shared library?

Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • 2
    Relocation costs extra indirection and increases code size, and you may wish to take that into account. But best to measure and compare! – Kerrek SB Oct 14 '15 at 20:42
  • 1
    Related: [Why does arm-linux-androideabi-gcc enforce -fpic?](http://stackoverflow.com/questions/14990461/why-does-arm-linux-androideabi-gcc-enforce-fpic) – Ivan Aksamentov - Drop Oct 14 '15 at 21:33

1 Answers1

2

Well, always compiling with -fPIC will produce a bit more bloated and a bit slower code.

Difference would be less visible on x64 target, I believe

You shall measure and decide if those differences are relevant for you app, you might be ok with it

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64