[C++-SIG] Re: C++ extension module crashes on Solaris

Steven E. Harris sharris at nospam.primus.com
Fri May 19 18:53:19 CEST 2000


The following message is a courtesy copy of an article
that has been posted to comp.lang.python as well.

"Daniel Berlin" <dan at cgsoftware.com> writes:

[...]

> No offense Guido, but you are probably completely off base.
> I'll put money it's a shared library problem.

[...]

Yes, well, I took Guido's advice and rebuilt Python without threading
support enabled. My goal (and problem, I belive) have nothing to do
with threading. I'll re-start from the beginning.

Following the instructions for the CXX kit, I set two environment
variables prior to configuring Python:

LINKCC    g++
LDSHARED  g++ -shared

I'm not entirely sure why this is necessary. If it's not, please
advise.

I ran the configure script as

$ ./configure --prefix=/users/sharris/usr/local

Everything configured fine, so I ran make, make test, and make
install. Next, I copied the file <pysrc>/Misc/Makefile.pre.in into my
module build directory and followed the directions in the Python
doc. called "Building C and C++ Extensions on Unix." My Setup file
looks like this (continuation lines for clarity here):

==================================================
# seh_test setup file
*shared*

CCC=g++

seh_test -I../Include \
         pod.cc \
         pypod.cc \
         seh_test.cc \
         ../Src/cxx_extensions.cxx \
         ../Src/cxxextensions.c \
         ../Src/cxxsupport.cxx
==================================================


A note about the directory structure context - it looks like this:


~/temp
      /Python-1.5.2         <== Python build tree (now installed)
      /CXX-4.2
              /Src          <== CXX source files
              /Include      <== CXX includes
              /seh_test     <== My test module stuff using CXX


My module builds okay, as evidenced here (again, line wraps are mine):

$ make
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c./pod.cc
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./pypod.cc
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./seh_test.cc
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./../Src/cxx_extensions.cxx
gcc -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./../Src/cxxextensions.c
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./../Src/cxxsupport.cxx
g++ -shared \
  pod.o pypod.o seh_test.o \
  cxx_extensions.o cxxextensions.o cxxsupport.o \
  -o seh_test.so


Next, I copy the built module into place and try to import it:

$ cp seh_test.so ~/usr/local/lib/python1.5/
$ python
Python 1.5.2 (#14, May 19 2000, 00:04:52)  [GCC 2.95.2 19991024 (release)] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import seh_test
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ImportError: ld.so.1: python: fatal: relocation error: file ./seh_test.so: symbol PyExc_IndexError: referenced symbol not found
>>>


Sigh. Okay, so I looked around on Deja for something relevant to this
error until I almost fell asleep, and finally found this suggestion:

Try passing the flags '-Wl,-E' to the linker.
http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=481811059&search=thread&threaded=1


So I reset the LDSHARED environment variable to 'g++ -shared -Wl,-E',
tore down the previous Python build, reconfigured it, and rebuilt it.

Python built and tested fine just like the last build. Looking over
the build output, it doesn't look like those linker options every got
used, since there weren't any shared objects getting built.

Finally, I tried rebuilding my test module, forcing the '-Wl,-E' flag
into the link line:

$ cp ~/temp/Python-1.5.2/Misc/Makefile.pre.in ./
$ make -f Makefile.pre.in boot LDSHARED='g++ -shared -Wl,-E'
$ make
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c./pod.cc
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./pypod.cc
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./seh_test.cc
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./../Src/cxx_extensions.cxx
gcc -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./../Src/cxxextensions.c
g++ -I../Include -g -O2 \
  -I/users/sharris/usr/local/include/python1.5 -DHAVE_CONFIG_H \
  -c ./../Src/cxxsupport.cxx
g++ -shared -Wl,-E \
  pod.o pypod.o seh_test.o \
  cxx_extensions.o cxxextensions.o cxxsupport.o \
  -o seh_test.so


Again, I copy the (re)built module into place and try to import it:

$ cp seh_test.so ~/usr/local/lib/python1.5/
$ python
Python 1.5.2 (#1, May 19 2000, 09:34:45)  [GCC 2.95.2 19991024 (release)] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import seh_test
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ImportError: ld.so.1: python: fatal: relocation error: file ./seh_test.so: symbol PyExc_IndexError: referenced symbol not found
>>>


Note that I can compile and use the CXX Demo application, which uses
both extension and embedding together. I can't get extending to work
alone, though.

What additional information can I provide to get some suggestions?

-- 
Steven E. Harris
Primus Knowledge Solutions, Inc.
http://www.primus.com




More information about the Cplusplus-sig mailing list