I'm trying to experiment with shared objects and found the below snippet on http://www.gambas-it.org/wiki/index.php?title=Creare_una_Libreria_condivisa_(Shared_Library)_.so

gcc -g -shared -Wl,-soname,libprimo.so.0 -o libprimo.so.0.0 primo.o -lc

I browsed trough the manpages and online, but I didn't find what the -lc switch does, can someone tell me?

  • 2
    the short answer is that in this case that option does nothing, because -lc (link to libc) will be added automatically by gcc's specs (unless -nodefaullibs or -nostdlib was used), as you can easily see by ommitting it and adding the -v option to gcc.
    – user313992
    Feb 14, 2019 at 14:43
  • 2
    ... and adding it yourself can mess things up, because there may be things (like crtend.o or libgcc.a) that need to be linked after all normal libraries but before the core C library.
    – zwol
    Feb 14, 2019 at 21:06

2 Answers 2


The option is shown as "-l_library_" (no space) or "-l _library_" (with a space) and c is the library argument,
see https://linux.die.net/man/1/gcc

-lc will link libc (-lfoobar would link libfoobar etc.)

General information about options and arguments

UNIX commands often accept option arguments with or without whitespace. If you have an option o which takes an argument arg you can write -o arg or -oarg. On the other hand you can combine options that don't take an argument, e.g. -a -b -c or -abc.
When you see -lc you can only find out from the documentation (man page) if this is the combination of options -l and -c or option -l with argument c or a single option -lc.

See also https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

Note: gcc is an exception from this general concept. You cannot combine options for gcc.

  • Thank you, the fact there wasn't a space led me to confusion.
    – DDS
    Feb 14, 2019 at 13:45
  • 2
    You cannot combine options with cc, even if they don't take any argument (you cannot write cc -cg instead of cc -c -g.
    – user313992
    Feb 14, 2019 at 16:15

-lc links with libc, the C library.

See the description of -llibrary in the documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .