Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
695 views
in Technique[技术] by (71.8m points)

ubuntu - Is lib{library name}.a / .so a naming convention for static libraries in Linux?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can name one any way you want, but ld's -l assuming a lib prefix applies to both static and shared libraries and goes back a long way; you'd need to name it explicitly to use one without the lib prefix.

This is actually useful even on modern systems: a name libfoo.so can be identified as a link-time library, while foo.so indicates a shared object implementing a runtime plugin. Or subsystem-specific prefixes in place of lib to identify plugins for particular subsystems; see for example pam_*.so and nss_*.so.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...