问题描述
尝试编译我的程序时出现无法解析的符号错误,抱怨它找不到__dso_handle
.此函数通常在哪个库中定义?
I have an unresolved symbol error when trying to compile my program which complains that it cannot find __dso_handle
. Which library is this function usually defined in?
nm on libstdc++.so.6
的以下结果是否表示包含该内容?
Does the following result from nm on libstdc++.so.6
mean it contains that?
我尝试链接它,但错误仍然出现.
I tried to link against it but the error still occurs.
nm libstdc++.so.6 | grep dso
00000000002fc480 d __dso_handle
推荐答案
__dso_handle
是"aguard",它是用于在全局销毁期间识别动态共享对象.
__dso_handle
is a "guard" that is used to identify dynamic shared objects during global destruction.
实际上,您应该在这里停止阅读.如果您想通过弄乱__dso_handle
来打败对象标识,则可能很不对劲.
Realistically, you should stop reading here. If you're trying to defeat object identification by messing with __dso_handle
, something is likely very wrong.
但是,由于您询问了它的定义位置,因此答案很复杂.要显示其定义的位置(对于GCC),请在C ++文件中使用iostream
,然后再执行extern int __dso_handle;
.由于类型冲突,这应该显示声明的位置(请参见此论坛主题(来源).
However, since you asked where it is defined: the answer is complex. To surface the location of its definition (for GCC), use iostream
in a C++ file, and, after that, do extern int __dso_handle;
. That should surface the location of the declaration due to a type conflict (see this forum thread for a source).
有时候,它是手动定义的.
有时,它是由编译器安装的运行时"定义/提供的(实际上,CRT通常只是一堆二进制标头/入口点管理代码,以及一些出口保护程序/处理程序).在GCC中(不确定其他编译器是否支持此功能;如果支持,它将在其源代码中提供):
Sometimes, it is defined/supplied by the "runtime" installed by the compiler (in practice, the CRT is usually just a bunch of binary header/entry-point-management code, and some exit guards/handlers). In GCC (not sure if other compilers support this; if so, it'll be in their sources):
- Main definition
- Testing
__dso_handle
replacement/tracker example 1 - Testing
__dso_handle
replacement/tracker example 2
通常在stdlib中定义:
Often, it is defined in the stdlib:
- Android
- BSD
进一步阅读:
- Subtle bugs caused by
__dso_handle
being unreachable in some compilers
这篇关于__dso_handle在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!