More on dynamic loading

Simeon H. Fitch (shf2d@banyan.cs.virginia.edu)
Wed, 13 Apr 1994 02:34:03 GMT

Many thanks to all of you who responded to my plea. After some more
investigation I have narrowed the problem down further. As a recap, I
am implementing a Python module in C++ that I want loaded at runtime.
I am using g++ v2.4.5 and ld under SunOS on a Sparc10.

First, it has nothing to do with the number of files that you link
together. It just happened in my previous case that several of the
extra objects that I was linking in were causing the problem (sorry).

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

For example, the following simple module dynamically creates an
integer and passes its value back to python.

----------C++----------

#include "allobjects.h"

object* test_demoTest(object* self, object* args) {

char* myString;
int* myInt;

if(!getargs(args, "s", &myString)) {
return NULL;
}
myInt = new int;

*myInt = 42;

return mkvalue("(si)", myString,*myInt);

}

static struct methodlist testMethods[] = {

{"demoTest", test_demoTest},
{NULL, NULL} // Sentinel

};

extern "C"
void
inittest() {

(void) initmodule("test", testMethods);

}

----------Python----------

import test
print test.demoTest('Hello world.')

--------------------

and the output should be:

('Hello world.', 42)

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.

Anyway, I'll keep hacking on this one and let ya'll know if I figure
anything out. This has got to be possible, right?

-Simeon-

-- 

+---------------------------------------------------------------------+ | Simeon H. Fitch Department of Computer Science | | fitch@Virginia.EDU University of Virginia | +---------------------------------------------------------------------+

Johann Gambolputty de von Ausfernschplenden schlitter crascrendon fried digger dingle dangle dongle dungle burstein von knacker thrasher apple banger horowitz ticolensic grander knotty spelltinkle grandlich grumblemeyer speltwasser kurstlich himbleeison bahnwagen gutenabend bitte ein nurnburger bratwustle gerspurten mitz weimache luber hundsfut gumberaber schvnendanker kalbsfleisch mittler aucher von Hautkopft of Ulm