首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Unix上执行共享库

在Unix上执行共享库
EN

Stack Overflow用户
提问于 2011-02-11 05:38:29
回答 1查看 3.1K关注 0票数 16

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

代码语言:javascript
复制
$ /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上问过这个问题。

EN

回答 1

Stack Overflow用户

发布于 2011-02-11 06:11:22

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

代码语言:javascript
复制
#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
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4963029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档