link static library (without -fPIC) to shared library on 64bit OS

安稳与你 提交于 2019-12-10 18:13:20

问题


I write programm in c++, from which will be made shared library - and done it will be used by JNI. I have 3rd party library ( libexample.a ) and need to link it to shared library ( libshared.so ). The problem is, that I work on 64bit CentOS and -fPIC is needed to create shared lib, but 3rd party library wasnt compiled with -fPIC.

Until building I recive: /usr/bin/ld: /home/tom/Project/src/libexample.a(SomeObject.o): relocation R_X86_64_32 against 'someData' can not be used when making a shared object; recompile with -fPIC

Is it possible to make shared library in this situation? (I dont have source code of libexample.a ...)

Is there any workaround to make it work? Even ideas when I will have to write additional apps.

I hope that my question isn`t duplicate (more or less) because I spent long time at searching of possibilities. Thanks, bez


回答1:


there was not way to make any workaround. I had to write to 3rd party library developers to compile once again with -fPIC




回答2:


Try this:

set_property(TARGET TheirLib PROPERTY POSITION_INDEPENDENT_CODE ON)

This will set the fPIC option on the 3rd party project.

Source for this answer



来源:https://stackoverflow.com/questions/13818921/link-static-library-without-fpic-to-shared-library-on-64bit-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!