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

前端 未结 5 1178
佛祖请我去吃肉
佛祖请我去吃肉 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:56

    You never needed to generate separate .o files. Always specify the compiler options to generate portable code (typically -fPIC).

    On some systems, the compiler may be configured to force this option on, or set it by default. But it doesn't hurt to specify it anyway.

    Note: One hopes that where PC-relative addressing is supported and performs well, that -fPIC uses that mode rather than dedicating an extra register.

提交回复
热议问题