[info-performer] dynamic loading of performer libraries

Date view Thread view Subject view Author view

From: C. Skluzacek (csklu_pf++at++yahoo.com)
Date: 06/14/2003 04:05:19


Hi,
I have a program that loads in plugin modules at
runtime using the libdl family of functions (I've also
tried using the gnu libtool library and got the same
result). I get a crash when I try to dynamically load
a plugin which itself depends on Performer. In test
code I've also tried dlopening libpf.so and looking
for (and running) the pfInit symbol, but that crashes
also. This has worked when I've indirectly loaded my
own(non-pf) code in this way. It of course runs when I
link libpf into the executable, but then that defeats
the purpose of the plugin functionality. My
configuration is: RH7.3, gcc3.2, pf3.0. Here is the
test code:

app.cpp:
--------
#include <iostream>
#include <dlfcn.h>

int main( int, char ** )
{
  void * handle = 0;
  char * error = 0;

#if 1 // open pfmodule and call function
  if ( (handle = dlopen("pfmodule.so", RTLD_GLOBAL |
RTLD_NOW )) == 0 ) {
    std::cerr<<dlerror()<<std::endl;
    exit(1);
  }

  void (*runPf)() = (void(*)())dlsym(handle,"runPf");
  if ( (error = dlerror()) != 0 )
std::cerr<<error<<std::endl;
  else if ( runPf ) (*runPf)();
  else std::cerr<<"runPf() address is 0\n";

#else // try loading performer library directly
  if ( (handle = dlopen("libpf.so", RTLD_GLOBAL |
RTLD_NOW)) == 0 ) {
    std::cerr<<dlerror()<<std::endl;
    exit(1);
  }
  void (*pfInit)() =
(void(*)())dlsym(handle,"pfInit");
  if ( (error = dlerror()) != 0 )
std::cerr<<error<<std::endl;
  else if ( pfInit ) (*pfInit)();
  else std::cerr<<"pfInit() address is 0\n";

#endif
  return 0;
}

pfmodule.cpp:
-------------
#include <iostream>
#include <Performer/pf.h>

extern "C" void runPf()
{
  std::cout<<"runPf()\n";
  pfInit();
  pfConfig();
  for ( ; ; ) {
    pfSync();
    pfFrame();
  }
}

Makefile:
---------
all: pfmodule.so app
pfmodule.o: pfmodule.cpp
        g++ -g -Wall -fPIC -DPIC -c -o $++at++ $<
pfmodule.so: pfmodule.o
        g++ -o $++at++ -shared -Wl,-soname=$++at++ $< -lpfdu -lpfutil
-lpf
app: app.cpp
        g++ -g -o $++at++ $< -Wl,--export-dynamic -ldl
clean:
        \rm pfmodule.o pfmodule.so app

Note: pfmodule.so is explicitly linked with libpf and
ldd does show the dependency

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Sat Jun 14 2003 - 04:06:04 PDT