views:

680

answers:

3

I have some c++ code I'm using for testing in which the first line is a call to dlopen in an attempt to load my shared object. Upon hitting this line I get the following error:

Terminate called after throwing an instance of std::bad_alloc: 
   what() : St9bad_alloc

I've upped the memory (free -m now reports that I have ~120 MB free when my exe is loaded in gdb) and I still get the same message.

Anyone any ideas on what else could be causing this & what I can do to resolve it?

+3  A: 

Take a look at the C++ dlopen mini HOWTO, hope that helps.

OneOfOne
A: 

It is probably because it can not find all its dependencies.

Change directory to the directory where you application lives.
Then use nm on the shared lib you are trying to load (Same path as you used in the code).
This will show any missing dependencies.

Martin York
+2  A: 

My guess is that dlopen has nothing to do with it. dlopen() is a C language function and it can't throw an exception. What can actually throw it is initialization functions in your shared objects, for example, the expressions you assign to your static objects. For example, if you write this in the shared object you're loading, it might crash with bad_alloc:

// dso.cpp start
#include <dso.h>

Object* instance = new Object();

// the rest of the file

But dlopen stuff is totally irrelevant, I suppose.

Pavel Shved