i have application loads library dlopen
, looks this:
#include <iostream> #include <dlfcn.h> void foo() { std::cout << "foo"; } int main() { void* libbar = dlopen("./libbar.so", rtld_lazy); if (!libbar) { std::cerr << dlerror() << std::endl; return 1; } void(*bar)() = (void(*)())dlsym(libbar, "bar"); if (!bar) { std::cerr << dlerror() << std::endl; return 1; } bar(); dlclose(libbar); }
and here libbar
:
#include <iostream> void foo(); extern "c" void bar() { foo(); std::cout << "bar" << std::endl; }
output:
./libbar.so: undefined symbol: _z3foov
expected output:
foobar
how make foo
visible libbar
?
i'm using c++ , real problem undefined symbols constructors/member functions, should similar. i'm working on linux gcc 4.7.
you should compile , link main.cc with
g++ -rdynamic -wall main.cc -o prog -ldl
the -rdynamic flag important @ link time.
and you'll better declare extern "c"
functions want pass dlsym
.
Comments
Post a Comment