gcc shared library failed linking to glibc

后端 未结 1 462
长情又很酷
长情又很酷 2020-12-29 14:26

I\'m writing a simple C shared library using Eclipse CDT under Linux 64bit.

The code has one reference to the rand() function in the

相关标签:
1条回答
  • 2020-12-29 15:01

    On x86_64 architecture gcc requires you to use -fPIC i.e Position Independent Code by default.

    The underlying reason for the error is that the relocation type for the symbol rand is of type R_X86_64_PC32 which means that it is PC relative and should lie within 32bit offset from the following instruction.

    But the current architecture is of x86_64 type which means that it can lie anywhere within the 64bit address space.

    So the dynamic linker actually can not link a symbol with such a relocation type.

    Either you have to use -fPIC or compile your code using the -mcmodel=large which will actually make the relocation type to R_X86_64_64.

    For more details on how linking is done refer to this great blog by Eli Bendersky

    0 讨论(0)
提交回复
热议问题