I’ve had to do some minor programming on a Ubuntu system recently (at which I am an extremely low-level beginner) and I’m really just getting familiar with makefiles.
I noticed that the arguments to tell the linker which libraries to include were always -l{library name} where the corresponding library would be something called “lib{library name}.a” in the /usr/lib folder.
I am wondering: is that a convention? I would have thought I would need to type -llibNAME to find a library called libNAME.a, but it seems to assume a lib prefix.
Is this always the case? Can I name a library without using a lib prefix?
You can name one any way you want, but
ld‘s-lassuming alibprefix applies to both static and shared libraries and goes back a long way; you’d need to name it explicitly to use one without thelibprefix.This is actually useful even on modern systems: a name
libfoo.socan be identified as a link-time library, whilefoo.soindicates a shared object implementing a runtime plugin. Or subsystem-specific prefixes in place oflibto identify plugins for particular subsystems; see for examplepam_*.soandnss_*.so.