12

I am creating a cross-platform program that depends on libxml2. I do not want to use a POSIX environment such as Cygwin or MSYS on the Windows port of the app. I am planning to create a system of build scripts using Javascript Host for Windows and nmake. But, the question arose of where the build system should look for libxml2. In what locations should it look when the user does not specify a location? On Linux, it is usually /usr/lib/ and /usr/local/lib/. But on Windows, the only place that comes to mind is C:\Windows\system32. But isn't that directory only modified by the system? (I obviously know next to nothing about the internals of Windows)

1 Answers1

10

The true equivalent of /usr/lib/ in Windows really is %windir%\system32, as it is always the (last) place where Windows looks for DLLs.

But simply dumping your libraries there is part of why DLL Hell is a thing. This is why the COM system was introduced; if your DLL is a "server module" for COM classes, you can register it (for instance through the regsvr32 utility), after which applications can dynamically link with its served classes through the CoCreateInstance() function. Here, the registry serves the purpose of /usr/lib/, but is completely different.

In modern Windows versions, the need for explicit registration is no longer needed with (registration-free) side-by-side assemblies. In fact, explicit deregistration of assemblies is sometimes needed to play nice with this new system. In this sense, %SystemRoot%\winsxs is the equivalent of /usr/lib/, but in an even more convoluted way.


Because of this mess, the answer to your underlying question --- "where should I look for libxml2?" --- is that "you won't find it". Unlike the operating systems that were made for modularity, you usually don't install separate libraries on Windows. If you want to build against libxml2, you either bundle the .lib file with your source, or tell the user to provide it. If you want to deploy a build, you deploy libxml2 along with your application (either statically linked, or as a DLL inside the application directory).

And even if it were installed system-wide, since libxml2 isn't made with Windows-specific concepts in mind, the only place to find it would be %windir%\system32. Nobody has the gall to place it there, though.


Note: I'm not very well versed in COM and .NET, so the above might not be completely accurate. If someone wants to improve upon this answer, I'm open to turning this into a community wiki.

  • Thank you. My approach will be to build libxml2 on Windows and link against the library, shipping it (not sure if I want static or dynamic) with my project. So the .dll or .lib file would be somewhere in the project directory tree before installation. –  Jul 06 '16 at 18:22
  • Actually `%windir%\system32` is equivalent of `/lib/` or `/lib64` in GNU/Linux... since user applications in Windows MUST NOT install their dependencies in `%windir%\system32`. https://stackoverflow.com/a/14446773/1429432 https://stackoverflow.com/a/2677931/1429432 – Yousha Aleayoub Mar 25 '21 at 11:43