0

When I run the shared library, It got executed. How this happened without main() program ? What is the entry point for starting the execution ?

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:~$ 
Lunar Mushrooms
  • 8,358
  • 18
  • 66
  • 88
  • possible duplicate of [Executing a shared library on Unix](http://stackoverflow.com/questions/4963029/executing-a-shared-library-on-unix), see also http://stackoverflow.com/questions/6899361/executable-shared-libraries – Mat Jun 30 '12 at 09:33

2 Answers2

3

Shared libraries do have the capability to have a main() function; it's just that most don't have one.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
3

Assuming you use GNU linker, you can specify the entrypoint with option -e entry (or --entry=entry in long option notation).

If you invoke the linker indirectly via gcc, use -Wl,-e,entry.

mity
  • 2,299
  • 17
  • 20