[ovs-dev] [PATCH] python/setup: "-fPIC" extra compile flag for C extension
Iwase Yusuke
iwase.yusuke0 at gmail.com
Wed Jan 11 02:33:52 UTC 2017
Hi,
I'm very sorry for disturbing you.
I found that this issue is not on Python extension.
I should have built openvswitch libraries with "--enable-shared" configure option.
Then, I could install Python extension successfully without my patch.
So, I would like to withdraw this patch...
Thanks,
Iwase
On 2017年01月11日 11:16, Iwase Yusuke wrote:
> Hi,
>
> On 2017年01月11日 11:01, Ben Pfaff wrote:
>> On Wed, Jan 11, 2017 at 09:38:13AM +0900, IWASE Yusuke wrote:
>>> To build shared library object, it is required to built as "Position
>>> Independent Code" (on x86-64, for example).
>>> This patch adds "-fPIC" extra compile flag to make sure that extension
>>> being PIC while building a shared library object.
>>>
>>> Signed-off-by: IWASE Yusuke <iwase.yusuke0 at gmail.com>
>>> ---
>>> python/setup.py | 9 +++++++--
>>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/python/setup.py b/python/setup.py
>>> index 19c1f18..8f565d8 100644
>>> --- a/python/setup.py
>>> +++ b/python/setup.py
>>> @@ -76,8 +76,13 @@ setup_args = dict(
>>> 'Programming Language :: Python :: 3',
>>> 'Programming Language :: Python :: 3.4',
>>> ],
>>> - ext_modules=[setuptools.Extension("ovs._json", sources=["ovs/_json.c"],
>>> - libraries=['openvswitch'])],
>>> + ext_modules=[
>>> + setuptools.Extension(
>>> + "ovs._json",
>>> + sources=["ovs/_json.c"],
>>> + libraries=['openvswitch'],
>>> + extra_compile_args=["-fPIC"]),
>>> + ],
>>> cmdclass={'build_ext': try_build_ext},
>>> )
>>
>> Are you sure that this is the right way to build a Python shared object?
>> It is very ELF-specific so I imagine that it will break Windows and BSD
>> builds.
>
> Sorry, I'm not good at C cross-platform building.
> I didn't test on such environment, tried it on only Ubuntu 16.04.
> When I built Python shared object, I need to add "-fPIC" to extension and
> also to openvswitch.a library, otherwise the followings would be output.
> ===
> /usr/bin/ld: //usr/local/lib/libopenvswitch.a(json.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
> ===
>
> I only know "shared object should be PIC", but don't understand
> enough why...
>
More information about the dev
mailing list