Where to put libraries and headers on windows (coming from unix?)

When a unix/linux program requires "stuff", I usually put (or dpkg puts for me) libraries and headers in /usr/lib and /usr/include, respectively.

I recently downloaded a library that I wish to use on windows, after recently doing so on my linux machine, that provides a download for a prebuilt windows binary. Of course, this comes with a .dll, a .lib, and a .h file that belong to the library.

My question is, is there any paradigm or pattern as to where I can put these files so that I can make use of them from several different programs/source files? The README supplied with the library made no mention of this, so forgive my ignorance coming from unix. Also, I'm using the command line/gcc toolchain, not VC.


Solution 1:

Typically the only libraries that are shared are those for Visual Studio, the .NET Frameworks, DirectX, and the Windows API. Other libraries are generally installed to each application directory. Typically if a library needs to be installed for shared use it will do one of two things:

  1. Install to it's own location under Program Files or Program Files\Common Files.
  2. Install to \Windows\System32 or (very rarely) \Windows. This is a throwback to how Windows worked about 10 years ago, and is considered poor practice (if not by programmers by administrators).

Ultimately, however, it doesn't matter where in the file system you put them as long as users have read access to them. Proper dynamic libraries are registered (most respond to regsvr32 <dllname> and regsvr32 /u <dllname>) so the applications which need them will ask the Windows Registry for the library it wants (based on GUID or class name) and the registry knows where the file is. The registry here is acting as a global catalog for installed libraries.

UPDATE:
For reference, here is how Windows searches for libraries you specify by library name.

If you specify the class you need, there are several ways to do that. For example you can use CoGetClassObject if you know the CLSID, which you can get using something like CLSIDFromProgID.

Solution 2:

My personal preferences is to do one of the following:

  1. Create a folder in \Program Files\ and put them there. If you need you can add the folder to the PATH, but if you need to register the .dll using regsvr32 you probably won't need to add it to PATH.
  2. Do the same as #1, except create it in a folder somewhere else

You can also put it in %SYSTEMROOT%, but I prefer to keep non Windows items out of that.