In Linux, I have a shared library I made that uses pthreads and a main.c that does not.
libpthread.so shows up in an ldd of my shared library, which is correct.
$ ldd libmapreduce.so.1.0
linux-gate.so.1 => (0x0067d000)
libpthread.so.0 => /lib/libpthread.so.0 (0x0058c000)
[...]
But when I compile and link my main.c that does not use pthreads to my shared library that does, I see:
$ icc -Wall -o main main.c -lmapreduce
/opt/intel/Compiler/11.1/046/lib/ia32/libiomp5.so: undefined reference to `pthread_atfork'
Adding -lpthread to my compile command, i.e.,
$ icc -Wall -o main main.c -lmapreduce -lpthread
resolves the undefined reference.
Why do I need to explicitly link to libpthread when my main.c does not use it and my shared library already has libpthread linked in?