简体   繁体   English

dlopen上的错误:St9bad_alloc

[英]Error on dlopen: St9bad_alloc

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. 我有一些用于测试的c ++代码,其中第一行是对dlopen的调用,以尝试加载共享对象。 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. 我已经调高了内存(free -m现在报告说,我的exe加载到gdb中时,我有〜120 MB的空闲空间),但我仍然收到相同的消息。

Anyone any ideas on what else could be causing this & what I can do to resolve it? 任何人对导致此问题的其他想法以及我该如何解决?

看看C ++ dlopen mini HOWTO ,希望对您有所帮助。

My guess is that dlopen has nothing to do with it. 我的猜测是dlopen与它无关。 dlopen() is a C language function and it can't throw an exception. dlopen()是C语言函数,它不能引发异常。 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: 例如,如果您在正在加载的共享对象中编写此代码,则它可能会因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. 但是,我认为dlopen完全无关紧要。

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). 然后在要加载的共享库上使用nm(与代码中使用的路径相同)。
This will show any missing dependencies. 这将显示所有丢失的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM