Why are some C++ dll names prefixed with lib, for example libxml2.dll? Does this has some significance?
-
no, the name prefix does not have any signifcance. – tromgy Oct 01 '21 at 11:20
-
It may refer to library, as in a dll with a library of functions but is not required – Pepijn Kramer Oct 01 '21 at 11:21
-
2When using GCC and its linker looks for libraries it will prepend `lib` to find libraries. So if you link with `xml2` then it will look for `libxml2.dll` (or possibly its export library `libxml2.a`). – Some programmer dude Oct 01 '21 at 11:21
-
It's mostly a nix thing. In Windows it's not common for libraries to start with it. – Michael Chourdakis Oct 01 '21 at 11:45
2 Answers
Libraries are used (referenced) at link time. Fore more details, check [SO]: LNK2005 Error in CLR Windows Form (@CristiFati's answer).
Nix considerations
According to [Man7]: LD(1):
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.
On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a ".so" extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.
In other words, it's possible to pass libraries to the GNU linker:
By name (base or with (absolute or relative) path)
Short form: -ldummy. In this case, the linker will search for libdummy.so (or libdummy.a).
Needless to say that if the .lib would be named dummy.so (or dummy.a), #2. would not work.
Win ecosystem
The libraries are passed to the default (VStudio) linker by name only ([MS.Learn]: .Lib Files as Linker Input).
However, some maintainers add the lib prefix just to be consistent with the Nix name.
So, it's just a convention and has no functional value whatsoever.
But nowadays, in order to reduce the gap between the 2 OSes, there are multiple Nix tool ports for Win (MinGW-w64, MSYS2, Cygwin, ...). Since those "obey" the Nix interface, you'd be able to use the short form (from previous chapter), and that would save a lot of headaches especially when porting large projects with Makefiles that contain -l.

- 38,250
- 9
- 50
- 87
-
The "Nix considerations" also apply to MinGW, so it could have some use on Windows. – HolyBlackCat Oct 04 '21 at 17:19
-
It is purely a convention and doesn't mean anything more than letting people know it is a library. You can call a dll anything you like

- 83
- 7