python-samplerate icon indicating copy to clipboard operation
python-samplerate copied to clipboard

Build breaks because -fPIC is missing: ld: error: relocation R_X86_64_32S cannot be used against local symbol; recompile with -fPIC

Open yurivict opened this issue 1 year ago • 5 comments

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '__stack_chk_guard'; recompile with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by samplerate.c
>>>               samplerate.c.o:(src_new) in archive _deps/libsamplerate-build/src/libsamplerate.a

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in _deps/libsamplerate-build/src/libsamplerate.a(src_linear.c.o)
>>> referenced by src_linear.c
>>>               src_linear.c.o:(linear_get_name) in archive _deps/libsamplerate-build/src/libsamplerate.a

ld: error: relocation R_X86_64_32S cannot be used against local symbol; recompile with -fPIC
>>> defined in _deps/libsamplerate-build/src/libsamplerate.a(samplerate.c.o)
>>> referenced by samplerate.c
>>>               samplerate.c.o:(src_new) in archive _deps/libsamplerate-build/src/libsamplerate.a

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in _deps/libsamplerate-build/src/libsamplerate.a(src_linear.c.o)
>>> referenced by src_linear.c
>>>               src_linear.c.o:(linear_get_description) in archive _deps/libsamplerate-build/src/libsamplerate.a

FreeBSD 14.0

yurivict avatar May 03 '24 18:05 yurivict

I had a similar issue trying to install within the AWS public.ecr.aws/lambda/python:3.11 Docker image for a lambda layer. My workaround was to add CFLAGS and (well most likely or would work) CXXFLAGS environment variables. Stripped down version of what worked for me:

FROM public.ecr.aws/lambda/python:3.11
ENTRYPOINT []

RUN yum install -y cmake3 gcc gcc-c++ git make
RUN ln -s /usr/bin/cmake3 /usr/bin/cmake

ENV CFLAGS="-fPIC"
ENV CXX_FLAGS="-fPIC"
RUN pip install samplerate

Epiphero avatar May 15 '24 21:05 Epiphero

I get the same error when building the wheel when trying to install it on fedora 40. It doesn't happen on ubuntu 24.04 or cachyos (arch based) and builds fine on those, not sure why there is the difference between distros - maybe some difference between default compile flags?

Edit, someone is also getting the same error on OpenSUSE in #17

oyvindln avatar May 17 '24 00:05 oyvindln

@oyvindln Have you tried the fix above? I don't know enough to decide if adding -fPIC by default is a good solution or not. It may depend on what compiler is used.

fakufaku avatar May 17 '24 05:05 fakufaku

Tested and doing CFLAGS="-fPIC" CXX_FLAGS="-fPIC" pip install samplerate inside a virtual python environment does make the install suceed so that is a workaround at least.

I don't really use fedora I was just testing if it was installable as I use it in a project.

oyvindln avatar May 18 '24 22:05 oyvindln

I just had that same issue with cibuildwheel here while building wheels for a project that depends on python-samplerate:

        /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: _deps/libsamplerate-build/src/libsamplerate.a(samplerate.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

I'd rather not use the -fPIC workaround because I don't want to change the way cibuildwheel does its magic.

vxgmichel avatar Jul 02 '24 14:07 vxgmichel

The -fPIC was added in v0.2.2. Please re-open if you still experience issues.

fakufaku avatar Oct 11 '25 00:10 fakufaku

I just ran into a similar issue with version 0.2.2, again while using cibuildwheel to build a project that depends on samplerate:

      [100%] Linking C shared module /tmp/pip-install-lswkie17/samplerate_18f9504306764815bb524063e9231359/build/lib.linux-x86_64-cpython-312/samplerate.cpython-312-x86_64-linux-gnu.so
      /opt/rh/gcc-toolset-14/root/usr/libexec/gcc/x86_64-redhat-linux/14/ld: _deps/libsamplerate-build/src/libsamplerate.a(samplerate.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

vxgmichel avatar Nov 16 '25 00:11 vxgmichel