Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyo3-build-config: For abi3, link to libpython3.so on Unix #2328

Closed
wants to merge 1 commit into from

Conversation

ravenexp
Copy link
Contributor

@ravenexp ravenexp commented Apr 24, 2022

Quoting PEP 384:

If Python is compiled as a shared library, it is installed as both
libpython3.so, and libpython3.y.so; applications conforming to this PEP
should then link to the former (extension modules can continue to link
with no libpython shared object, but rather rely on runtime linking).

Source: https://peps.python.org/pep-0384/#linkage

@ravenexp
Copy link
Contributor Author

Previous discussion: #2324 (comment)

Quoting PEP 384:

 If Python is compiled as a shared library, it is installed as both
 libpython3.so, and libpython3.y.so; applications conforming to this PEP
 should then link to the former (extension modules can continue to link
 with no libpython shared object, but rather rely on runtime linking).

Source: https://peps.python.org/pep-0384/#linkage
@ravenexp ravenexp marked this pull request as draft April 24, 2022 12:45
@ravenexp
Copy link
Contributor Author

Ok, I'm not sure if -lpython3 even works with modern gcc toolchains...

When compiling a C program that only calls Py_Initialize():

$ gcc test.c -lpython3
/usr/bin/ld: /tmp/ccQwlIiy.o: undefined reference to symbol 'Py_Initialize'
/usr/bin/ld: /usr/lib/libpython3.10.so.1.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Adding a workaround makes it kinda work:

$ gcc test.c -Wl,--copy-dt-needed-entries -lpython3
$ ./a.out
$ ldd a.out
        linux-vdso.so.1 (0x00007ffc38b86000)
        libpython3.so => /usr/lib/libpython3.so (0x00007f19c8d47000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f19c8b3d000)
        libpython3.10.so.1.0 => /usr/lib/libpython3.10.so.1.0 (0x00007f19c8782000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f19c8d6f000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f19c869a000)

but, it only results in the executable linking to both libpython3.so and libpython3.10.so.

I'm going to conclude that this part of PEP 384 is dead on arrival, because I couldn't find anyone complaining about it not working as intended except for https://bugs.python.org/issue11347.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant