Does one still need to use -fPIC when compiling with GCC?

前端 未结 5 1175
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-20 12:26

On gcc target machines, when one wanted to compile a shared library, one would need to specify -fpic or -fPIC to get things to work correcly. This is because by default absolute

5条回答
  •  独厮守ぢ
    2021-02-20 12:49

    I agree with you: in many cases the -fpic/-fPIC options are almost redundant, I do however use them to ensure:

    • portability (never sure what particular OS/kernel will be available)
    • backwards compatibility: with those options it ensures the behaviour you want on older kernels
    • habit - Hard things to break :)
    • compliance with older codebases that may require it

提交回复
热议问题