在 Unix 上执行共享库 [英] Executing a shared library on Unix
本文介绍了在 Unix 上执行共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
某些 Unix 共享库在从命令行调用时提供输出,就好像它们是可执行文件一样.例如:
Some Unix shared libraries provide an output when called from the command line as if they were executables. For example:
$ /lib/libc.so.6
GNU C Library stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.5.2.
Compiled on a Linux 2.6.37 system on 2011-01-18.
[...]
在我自己用 C 编写的共享库中,我如何提供此输出?我现在已经执行了我刚刚创建的库,但出现了段错误.
In a shared library of my own written in C, how can I provide this output? I've executed now a library I just made and I get a segment fault.
注意:我之前在 Unix & 上问过这个问题Linux SE 此处.
Note: I asked this previously on Unix & Linux SE here.
推荐答案
下面的 main 定义负责打印你看到的输出.它在 glibc 的源代码树的 csu/version.c 中定义.我希望这会有所帮助.
The below definition of main is responsible for printing the output you see. It is defined in csu/version.c of the source tree of glibc. I hope this helps.
#ifdef HAVE_ELF
/* This function is the entry point for the shared object.
Running the library as a program will get here. */
extern void __libc_main (void) __attribute__ ((noreturn));
void
__libc_main (void)
{
__libc_print_version ();
_exit (0);
}
#endif
这篇关于在 Unix 上执行共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文