There have been various issues with this over the years, usually caused by differences in the way libpython is linked on Linux vs Mac vs Windows. In 2023 I fixed it on Mac by making runtime/build.gradle run a Python script that prints sys.base_prefix. But the build is still failing on Linux:
> Task :runtime:cmakeBuild-host
[1/4] Building C object CMakeFiles/chaquopy_java.dir/build/cython/chaquopy_java.c.o
[2/4] Linking C shared library libchaquopy_java.so
FAILED: libchaquopy_java.so
: && /usr/bin/cc -fPIC -g -shared -Wl,-soname,libchaquopy_java.so -o libchaquopy_java.so CMakeFiles/chaquopy_java.dir/build/cython/chaquopy_java.c.o -L/home/smith/.pyenv/versions/3.8.12/lib -Wl,-rpath,/home/smith/.pyenv/versions/3.8.12/lib -lpython3.8 && :
/usr/bin/ld: /home/smith/.pyenv/versions/3.8.12/lib/libpython3.8.a(abstract.o): relocation R_X86_64_PC32 against symbol `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/smith/.pyenv/versions/3.8.12/lib/libpython3.8.a(boolobject.o): relocation R_X86_64_PC32 against symbol `_Py_FalseStruct' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/smith/.pyenv/versions/3.8.12/lib/libpython3.8.a(bytearrayobject.o): relocation R_X86_64_PC32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC
...
/usr/bin/ld: /home/smith/.pyenv/versions/3.8.12/lib/libpython3.8.a(parser.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/smith/.pyenv/versions/3.8.12/lib/libpython3.8.a(myreadline.o): relocation R_X86_64_PC32 against symbol `_PyOS_ReadlineTState' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
There have been various issues with this over the years, usually caused by differences in the way libpython is linked on Linux vs Mac vs Windows. In 2023 I fixed it on Mac by making runtime/build.gradle run a Python script that prints
sys.base_prefix
. But the build is still failing on Linux: