在Unix上执行一个共享库

某些Unix共享库在从命令行调用时提供输出,就像它们是可执行文件一样。 例如:

$ /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编写的共享库中,如何提供这个输出? 我现在已经执行了一个我刚刚创build的库,并且出现了段错误。

注意:我以前在unix.stackechange.com上询问过这个问题https://unix.stackexchange.com/questions/7066/executing-a-shared-library

main的下面定义负责打印你看到的输出。 它在glibc的源码树的csu / version.c中定义。 我希望这有帮助。

 #ifdef HAVE_ELF
 / *这个函数是共享对象的入口点。
   作为一个程序运行图书馆将到达这里。  * /

 extern void __libc_main(void)__attribute__((noreturn));
空虚
 __libc_main(void)
 {
   __libc_print_version();
   _exit(0);
 }
 #万一