Bug 1812598

Summary: Missing linker flags in pc file
Product: [Fedora] Fedora Reporter: Alexis Jeandet <alexis.jeandet>
Component: python3Assignee: Charalampos Stratakis <cstratak>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 32CC: cstratak, dmalcolm, m.cyprian, mhroncok, pviktori, python-sig, rkuska, shcherbina.iryna, slavek.kabrda, tomspur, torsava, vstinner
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-11 16:43:58 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Alexis Jeandet 2020-03-11 16:24:43 UTC
Description of problem:

Curent PC file looks like this:

# See: man pkg-config
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib64
includedir=/usr/include

Name: Python
Description: Build a C extension for Python
Requires:
Version: 3.8
Libs.private: -lcrypt -lpthread -ldl  -lutil -lm
Libs:
Cflags: -I${includedir}/python3.8


It should be more like this:

# See: man pkg-config
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib64
includedir=/usr/include

Name: Python
Description: Build a C extension for Python
Requires:
Version: 3.8
Libs.private: -lcrypt -lpthread -ldl  -lutil -lm
Libs: -L${libdir} -lpython3.8
Cflags: -I${includedir}/python3.8


Version-Release number of selected component (if applicable):
python3-3.8.2-2

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Miro Hrončok 2020-03-11 16:35:32 UTC
This is intended. Extension modules are not to be linked with libpython. See https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build

"On Unix, C extensions are no longer linked to libpython except on Android and Cygwin. It is now possible for a statically linked Python to load a C extension built using a shared library Python.

...


To embed Python into an application, a new --embed option must be passed to python3-config --libs --embed to get -lpython3.8 (link the application to libpython). To support both 3.8 and older, try python3-config --libs --embed first and fallback to python3-config --libs (without --embed) if the previous command fails.

Add a pkg-config python-3.8-embed module to embed Python into an application: pkg-config python-3.8-embed --libs includes -lpython3.8. To support both 3.8 and older, try pkg-config python-X.Y-embed --libs first and fallback to pkg-config python-X.Y --libs (without --embed) if the previous command fails (replace X.Y with the Python version).

On the other hand, pkg-config python3.8 --libs no longer contains -lpython3.8. C extensions must not be linked to libpython (except on Android and Cygwin, whose cases are handled by the script); this change is backward incompatible on purpose."


There are two "PC files":

/usr/lib64/pkgconfig/python-3.8-embed.pc
/usr/lib64/pkgconfig/python-3.8.pc

Respectively:

/usr/lib64/pkgconfig/python3-embed.pc
/usr/lib64/pkgconfig/python3.pc



To build extension modules, use python-3.8.pc (python3.pc). To embed Python, use python-3.8-embed.pc (python3-embed.pc):


$ grep Libs: /usr/lib64/pkgconfig/python-3.8.pc 
Libs:

$ grep Libs: /usr/lib64/pkgconfig/python-3.8-embed.pc 
Libs: -L${libdir} -lpython3.8

Comment 2 Miro Hrončok 2020-03-11 16:36:19 UTC
Alexis, please let me know how are you actually experiencing the problem.

Comment 3 Alexis Jeandet 2020-03-11 16:43:58 UTC
Hi Miro,

Thank you for the explanation, I didn't know this change, I got this while building one of my codes with Meson where I basically do:

pymod = import('python')
python3 = pymod.find_installation('python3', modules:['PySide2','shiboken2', 'shiboken2_generator', 'numpy'])
python3_dep = python3.dependency()
....
executable('sciqlop', 'main.cpp', dependencies :python3_dep)

And reading the Meson doc:
https://mesonbuild.com/Python-module.html#dependency
I see 

embed: (since 0.53.0) If true, meson will try to find a python dependency that can be used for embedding python into an application.


Sorry for the noise...

Comment 4 Miro Hrončok 2020-03-11 17:27:37 UTC
> Sorry for the noise...

Don't be. I've put a note in https://fedoraproject.org/wiki/Changes/Python3.8#Release_Notes so we don't forget to document this change properly. You are not the first one to ask about it.