某些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编写的共享库中,我如何提供此输出?我现在已经执行了一个我刚刚创建的库,我得到了一个段错误。
注意:我之前在Unix和Linux SE here上问过这个问题。
发布于 2011-02-11 06:11:22
下面的main定义负责打印您看到的输出。在glibc源树的csu/version.c中定义。我希望这能帮到你。
#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
https://stackoverflow.com/questions/4963029
复制相似问题