Following command compiles/links fine and program runs without errors. When I add -static option, I get link error: undefined reference clock_gettime(). No other errors or differences exist and everything else links OK.
Because you don’t have rt.a installed (see #3 below).
Is there a way to dump exactly what is in a lib, i.e. what is the exact prototype of the functions included and what criteria the linker uses?
You can use objdump and other binutils, though this is not often needed - in this case, the errors are simply because the linker can’t find the static lib, so the reference is unresolvable. But I do know what you mean - sometimes you can’t help but wonder “is it really in there?” If I really can’t believe the linker won’t resolve correctly, I usually check with:
Ahh . . I see - sorry. I must admit, I’m not much of a pthreads guy, so I’m afraid I don’t have a lot of other suggestions. Though it looks correct to me, have your tried altering the order libraries you are linking to (-l pthread -l rt)? Just thinking of the link order of libraries, as for example in An Introduction to GCC - Link order of libraries