FAQ
I'm starting to feel incredibly stupid here. Hopefully someone can
point out a really obvious thing that I've missed, thus enabling me to
move forward!

Up until now, I've been embedding Python 2.6.6 in my C++ program, by
compiling with "-I/usr/include/python2.6 -lpython2.6", and all has
been well. The Python I use was installed as part of Ubuntu's setup,
and is managed by apt-get. Now, I'm trying to switch to using Python
3. so I downloaded the 3.2 sources and did the usual './configure;
make; sudo make install', then snooped to see where it had put things.
I'm now compiling with "-I/usr/local/include/python3.2m -lpython3.2m",
and it's compiling successfully (now that I've changed the function
names eg PyString --> PyBytes), but the link fails with heaps of
undefined references - as far as I can tell, every single Py*
reference is failing.

There is a libpython3.2m.a accessible, and poking around with ar and
nm shows that it does contain object files with the necessary symbols.
If I deliberately misspell the -lpython3.2m option, the link bombs
immediately, so presumably it IS finding the library. Explicitly
naming the library as ~/Python-3.2/libpython3.2m.a (or using ar to
extract them and then linking against the whole directoryful of .o
files, which does the same thing) cures the undefined references to
Py* functions, but brings in undefined refs to dlsym and openpty and
family.

Is/are there additional library/ies that I need to be linking against
for Python 3? And why is the usual -lpython3.2m not working as normal?
Is there a problem with C++ and Python? (I tried surrounding #include
"Python.h" with extern "C" { }, but to no avail.)

Hoping that someone has already done this!

Chris Angelico

Search Discussions

  • Chris Angelico at May 25, 2011 at 8:53 am
    Followup. I'm now using Python 3.3 straight from Mercurial, and am
    seeing the same issues. I've managed to get the compilation step to
    succeed by naming the library for full inclusion and adding -lutil
    -ldl (sounding rather Donizetti there), and my program runs. However,
    it's unable to import all its modules. I can happily import re,
    string, and sys, but importing math or time results in an ImportError
    citing "undefined symbol: PyExc_ValueError". I think there's still
    something I'm mucking up in the link process.

    The exception is ImportError, with text:
    '/usr/local/lib/python3.3/lib-dynload/time.cpython-33m.so: undefined
    symbol: PyExc_ValueError'

    Any ideas?

    Chris Angelico
  • Chris Angelico at May 27, 2011 at 12:55 am
    Still trying to sort this out, trying various things. If I configure
    --enable-shared, I get a different ImportError: 'libpython3.3m.so.1.0:
    cannot open shared object file: No such file or directory'. That file
    exists in ~/cpython, but sudo make install doesn't put it anywhere
    else. Pointing LD_LIBRARY_PATH to there causes my program to segfault
    with thread context errors.

    Am I asking this in the wrong forum? Would it be more appropriate in python-dev?

    Chris Angelico
  • Ned Deily at May 27, 2011 at 2:45 am
    In article <BANLkTim=j9wZZv7oWPpmaWxZ52u2AoPmSQ at mail.gmail.com>,
    Chris Angelico wrote:
    Still trying to sort this out, trying various things. If I configure
    --enable-shared, I get a different ImportError: 'libpython3.3m.so.1.0:
    cannot open shared object file: No such file or directory'. That file
    exists in ~/cpython, but sudo make install doesn't put it anywhere
    else. Pointing LD_LIBRARY_PATH to there causes my program to segfault
    with thread context errors.

    Am I asking this in the wrong forum? Would it be more appropriate in
    python-dev?
    The discussion in http://bugs.python.org/issue4434 might be of some help.

    --
    Ned Deily,
    nad at acm.org
  • Chris Angelico at May 27, 2011 at 7:14 am

    On Fri, May 27, 2011 at 12:45 PM, Ned Deily wrote:
    The discussion in http://bugs.python.org/issue4434 might be of some help.
    Thanks Ned! That was most helpful. I'm still not sure exactly what I
    changed, but between building with --enable-shared and some fiddling
    with how I link my program, I've managed to get it all to work. Now to
    start clean on a different box and try to deploy it... if I can do
    that, then it's definitely working.

    Chris Angelico

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 25, '11 at 12:16a
activeMay 27, '11 at 7:14a
posts5
users2
websitepython.org

2 users in discussion

Chris Angelico: 4 posts Ned Deily: 1 post

People

Translate

site design / logo © 2022 Grokbase