Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > dlclose an RTLD_GLOBAL

Reply
Thread Tools

dlclose an RTLD_GLOBAL

 
 
diegofsantos@gmail.com
Guest
Posts: n/a
 
      03-28-2007
Hi,
I have created an C++ application that uses shared libs (plugins -
object factories). I need
to load and unload the libs at run time.
I need to open the shared libs with RTLD_GLOBAL parameter and I open
all shared libs without any problems. But when I try to unload the
libs (dlclose), my application crashs (segmentation fault). If I dont
use RTLD_GLOBAL, all works fine.

Here are a piece of my code that loads the libs:

while ( (temp=man->getActiveNameFromFile())!=NULL)
{
void *dlib;

dlib = dlopen(temp,RTLD_NOW|RTLD_GLOBAL);
liblist.push_back(dlib);
if (dlib == NULL)
{
fl_alert(dlerror());
}
}


Note that I put all handles (void *) in a std::list. The dlopen
works fine, all libs are loaded.
Then, I try to unload all libs as the following:

std::list<void *>::iterator it;

for (it=liblist.begin(); it!=liblist.end(); it++)
if (dlclose(*it))
printf("\nErro\n");

But the applications always crash here.

I have tried to use dlclose in reverse order too without success.

Please, can anyone help me?

I'd like to load and unload the shared libs dynamically, but I
couldn't unload it.

Thanks in advance,

Diego

 
Reply With Quote
 
 
 
 
Piyo
Guest
Posts: n/a
 
      03-28-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
> I have created an C++ application that uses shared libs (plugins -
> object factories). I need
> to load and unload the libs at run time.
> I need to open the shared libs with RTLD_GLOBAL parameter and I open


Can you explain why you need to load symbols globally instead of
locally?

> all shared libs without any problems. But when I try to unload the
> libs (dlclose), my application crashs (segmentation fault). If I dont
> use RTLD_GLOBAL, all works fine.


It may be the case that some symbol in all of your plugin is trumping
a symbol in your global namespace on loading. Then you unload it but the
program still requires that symbol. This might cause your problem.

Other sources of shared libs crashes are globals
(static or otherwise) or hanging onto any references to objects
instantiated by your plugin. If you do not destroy all globals and/or
refs to objects and then you unload the plugin, the object destructor
is now invalid.

HTH!!
 
Reply With Quote
 
 
 
 
Piyo
Guest
Posts: n/a
 
      03-28-2007
(E-Mail Removed) wrote:
> Hi,
> I have created an C++ application that uses shared libs (plugins -
> object factories). I need
> to load and unload the libs at run time.
> I need to open the shared libs with RTLD_GLOBAL parameter and I open


Can you explain why you need to load symbols globally instead of
locally?

> all shared libs without any problems. But when I try to unload the
> libs (dlclose), my application crashs (segmentation fault). If I dont
> use RTLD_GLOBAL, all works fine.


It may be the case that some symbol in all of your plugin is trumping
a symbol in your global namespace on loading. Then you unload it but the
program still requires that symbol. This might cause your problem.

Other sources of shared libs crashes are globals
(static or otherwise) or hanging onto any references to objects
instantiated by your plugin. If you do not destroy all globals and/or
refs to objects and then you unload the plugin, the object destructor
is now invalid.

HTH!!
 
Reply With Quote
 
diegofsantos@gmail.com
Guest
Posts: n/a
 
      03-28-2007
> Can you explain why you need to load symbols globally instead of
> locally?



When I try to load symbols locally, I can load and unload libs, but my
application doesnt work fine. I have a base class for all plugins
named moduleBase, as the following:

class moduleBase
{
public:

.
.
.
virtual void setInput (itk:ataObject *in);
virtual void setInput (itk:ataObject *in, int port);
virtual itk:ataObject *getOutput();
virtual itk:ataObject *getOutput(int port);
virtual bool update();
virtual bool run();
void init_module();
.
.
.


The problem is the following: the output of one plugin is an input of
another, and so on... and in the plugin .cxx file I do casting
(itk:ataObject to another type). When I load symbols locally, I
can't do the casting... here is the error:
"cannot cast PKN3itk10DataObjectE to PKN3itk9ImageBaseILJ3EEE"


But if I load the libs with RTLD_GLOBAL, then all works fine.

Could you help me? May I have load the symbols locally ? How can I
solve this problem?

Thanks in advance,
Diego



On Mar 28, 3:15 pm, Piyo <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Hi,
> > I have created an C++ application that uses shared libs (plugins -
> > object factories). I need
> > to load and unload the libs at run time.
> > I need to open the shared libs with RTLD_GLOBAL parameter and I open

>
> Can you explain why you need to load symbols globally instead of
> locally?
>
> > all shared libs without any problems. But when I try to unload the
> > libs (dlclose), my application crashs (segmentation fault). If I dont
> > use RTLD_GLOBAL, all works fine.

>
> It may be the case that some symbol in all of your plugin is trumping
> a symbol in your global namespace on loading. Then you unload it but the
> program still requires that symbol. This might cause your problem.
>
> Other sources of shared libs crashes are globals
> (static or otherwise) or hanging onto any references to objects
> instantiated by your plugin. If you do not destroy all globals and/or
> refs to objects and then you unload the plugin, the object destructor
> is now invalid.
>
> HTH!!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unresolved symbols dlclose, dlopen, dlerror, dlsym me2faster@excite.com Ruby 8 05-17-2005 07:30 PM



Advertisments