build: try calling python-config with --embed
authorSimon Marchi <simon.marchi@efficios.com>
Sun, 29 Dec 2019 22:27:04 +0000 (17:27 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Jan 2020 20:15:24 +0000 (15:15 -0500)
To get the flags required to link an application with Python 3.8 (such
as to embed Python in the application), it is necessary to use the
"--embed" flag of python-config.  These flags include "-lpython3.8".
Without "--embed", the printed flags are for building a Python
extension.  These don't require being linked with the Python library,
since they are dlopen'ed by the library itself.

Our Python plugin provider requires being linked with Python, since it
embeds a Python interpreter.  Since we don't use "--embed" currently
when getting link flags, we don't link with the Python library, and
therefore the provider is not usable with Python 3.8.

The solution proposed here:

  https://docs.python.org/3/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build

is to try calling python-config with --embed first, and then without if
that didn't work.  With this patch, I am able to use the Python plugin
provider with Python 3.8.

Change-Id: I0c0e61dd3bded853abf124c651efe98ee7700101
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2726
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
configure.ac

index b1edd9ee85421c43e40774f01590bdbcf17747e6..7cbe3ba72220b691074dfd5a2a5d228cc6a1dbd0 100644 (file)
@@ -510,7 +510,10 @@ AM_PATH_PYTHON([3.0], [
 
     AS_IF([test -z "$PYTHON_LDFLAGS"], [
       AC_MSG_CHECKING([Python library flags])
-      PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags`
+      # Python 3.8+ requires that we pass --embed to get the -lpython3.x flag.
+      AS_IF([! PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags --embed`], [
+        PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags`
+      ])
       AC_MSG_RESULT([$PYTHON_LDFLAGS])
     ])
   ])
This page took 0.025086 seconds and 4 git commands to generate.