Linking embedded python?

Andrew Sobala andrew at sobala.net
Thu Dec 26 14:38:29 EST 2002


I may have answered my own question. This seems to work (posting here in
case anyone finds it useful in the future) to put in configure.in to
find cflags and libs that you need to put in the compile options (those
were google keywords :-))

AC_CHECK_PROG(python_val, python, true, false)
AC_MSG_CHECKING(for Python libraries)
HAVE_PYTHON=1
if $python_val; then
  PY_PREFIX=`python -c 'import sys ; print sys.prefix'`
  PY_EXEC_PREFIX=`python -c 'import sys ; print sys.exec_prefix'`
  changequote(<<, >>)dnl
  PY_VERSION=`python -c 'import sys ; print sys.version[0:3]'`
  changequote([, ])dnl
  if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h; then
    PY_LIBS="-lpython$PY_VERSION"
    PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
    PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
    PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile"
    PY_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p'
$PY_MAKEFILE`
    PY_BASEMODLIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
    PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE`
    PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASEMODLIBS $PY_OTHER_LIBS"
    AC_MSG_RESULT([version $PY_VERSION])
    CFLAGS=$PY_CFLAGS
    LIBS="$PY_LIB_LOC $PY_LIBS $PY_EXTRA_LIBS"
  else
    AC_MSG_ERROR([Can't find Python headers or libraries.])
  fi
else
  AC_MSG_ERROR([Can't find Python headers or libraries.])
fi

I haven't actually tested how well this works, but it seems to.

-- 
                 Merry Christmas,

                               Andrew

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GS/M d--(-) s: a17 C++(+++) UL+ P++ L+++ E--- W+>++ N(-) o? K? w--(---) !O M V-
PS+ PE Y+ PGP+>++++ t@ 5-- X- R tv-@ b++++ DI+++ D>---- G- e- h! r--- y?
------END GEEK CODE BLOCK------





More information about the Python-list mailing list