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

Lyle Johnson jlj at cfdrc.com
Fri May 19 20:39:14 CEST 2000


Steven,

I'm coming into this thread a little late and so I hope I'm not repeating
advice you've already heard and tried. When I compile C++ in general for use
as a Python extension module, I use these flags to compile the individual
files:

	g++ -fPIC -c file1.cpp
	g++ -fPIC -c file2.cpp

and then for the link step:

	g++ -Wl,-E -shared -o seh_test.so file1.o file2.o ...

I noticed in particular that you are not using the "-fPIC" flag for the
compile step. I know that this is REQUIRED on most platforms for this to
work properly, so it might be the missing piece of the puzzle in your case.

Apologies in advance if this is a false lead. I'm not using CXX but am
(successfully) compiling C++ code into Python extensions, using g++.

Lyle

> -----Original Message-----
> From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
> Behalf Of Steven E. Harris
> Sent: Friday, May 19, 2000 11:53 AM
> Cc: c++-sig at python.org
> Subject: [C++-SIG] Re: C++ extension module crashes on Solaris
>
>
> 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=threa
> d&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
>
> _______________________________________________
> C++-SIG maillist  -  C++-SIG at python.org
> http://www.python.org/mailman/listinfo/c++-sig
>





More information about the Cplusplus-sig mailing list