Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some shared libraries provide an output when called from the command line as if they were executables. For example:

$ /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
Compiled by GNU CC version 4.5.2.
Compiled on a Linux 2.6.37 system on 2011-01-18.

In a shared library of my own written in C, how can I provide this output? I've executed now a library I just made and I get a segment fault.

share|improve this question
Seems a topic for Stack Overflow. – Tshepang Feb 7 '11 at 21:08
Thank you. I'v now asked this there. stackoverflow.com/questions/4963029/… – franziskus Feb 10 '11 at 21:39

Try defining a void __libc_main() or void _init().

share|improve this answer
Thank you. It does not work for me, code in __libc_main() does not seem to be called and I get a segment fault (perhaps before calling it?), _init() cannot be linked because this function is already defined by /usr/lib/gcc/x86_64-unknown-linux-gnu/4.5.2/../../../../lib/crti.o:initfini.c – franziskus Feb 8 '11 at 6:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.