某些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.stackechange.com上问过
https://unix.stackexchange.com/questions/7066/executing-a-shared-library
下面的主要定义是负责打印您看到的输出。它在glibc的源码的csu / version.c中定义。我希望这有帮助。
原文链接:https://www.f2er.com/bash/387404.html#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