Re: More on dynamic loading
Wed, 13 Apr 1994 14:58:59 +0200
> It turns out that my problem is with certain C++ operators and
> objects, particularly (but I doubt limited to) 'new' and 'cerr'. The
> dynamic loader does not seem to be able to resolve these names.
> I create my module with the following:
> g++ -c testmodule.C -o testmodule.o
> ld -o testmodule.so testmodule.0 -lg++
> Whenever I try to load the object in Python I get the error:
> ld.so: Undefined symbol: ___builtin_new
> Sure, for this case I could just use malloc (yuck) insead of new, but
> I will still have the same problem when I want dynamic creation of
> classes. I also get an undefined symbol error if I use 'cerr' or
> 'cout', etc., which leads me to believe that something that is
> supposed to get linked in, isn't, although I would have thought that
> these C++ constructs would have been covered by the inclusion of
> '-lg++' in the making of the .so file.
Yes, the crux of your problem is that you need to provide C++ runtime
library support (__builtin_new, cerr etc.) in addition to C runtime
library support (malloc, stderr etc.). Since the Python interpreter
is linked as a C program it does not provide C++ runtime support.
I would think that your -lg++ should already take care of this. Maybe
there's ANOTHER library (linked by default by g++) that you also need?
(Try something like g++ --verbose on a simple main.c program to see
what libraries it links with.)
--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>