在没有main()的情况下执行共享库

时间:2012-06-30 09:22:56

标签: c linux gcc shared-libraries

当我运行共享库时,它已被执行。没有main()程序怎么回事?开始执行的切入点是什么?

ubuntu@ubuntu:~$ /lib/i386-linux-gnu/libc.so.6

GNU C Library (Ubuntu EGLIBC 2.15-0ubuntu10) stable release version 2.15, by Roland McGrath et al.
Copyright (C) 2012 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.6.3.
Compiled on a Linux 3.2.14 system on 2012-04-19.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.
ubuntu@ubuntu:~$ 

2 个答案:

答案 0 :(得分:3)

共享库确实具有具有 main()功能的能力;只是大多数都有一个。

答案 1 :(得分:3)

假设您使用GNU链接器,您可以使用选项-e entry(或长选项表示法中的--entry=entry)指定入口点。

如果您通过gcc间接调用链接器,请使用-Wl,-e,entry