1

Why are some C++ dll names prefixed with lib, for example libxml2.dll? Does this has some significance?

CristiFati
  • 38,250
  • 9
  • 50
  • 87

2 Answers2

3

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:

  1. By name (base or with (absolute or relative) path)

  2. 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.

CristiFati
  • 38,250
  • 9
  • 50
  • 87
2

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

Colin M
  • 83
  • 7