The notorious error 126 (ERROR_MOD_NOT_FOUND) when loading DLL/DSO's in Win32


Some people suffer from this error when loading Apache modules, which are DLL's (or modules, such as Apache's DSO's). NOTE: the information I gathered from the net shows this is a general problem with software using DLL's.

ERROR_MOD_NOT_FOUND The specified module could not be found.

is all you are going to find in the helpful Microsoft documentation. Searching the net produces a wad of desperate emails and almost no solutions that giveth the sufferer hope at salvation. However, there's one that might be The One...

I've taken liberty to 'loan' quite a bit of the text and help provided there and apply it to mod_bandhwidth.so loading trouble as reported by Steve Potts. Unfortunately I couldn't produce the 'error 126' on my own system, so that's not making things any easier.

What is causing error 126?

An (adjusted) quote:

"The specified file could be located, but could not be loaded. [...] The mentioned DLL is one that [Apache] attempts to load from [the 'modules' directory as specified by the LoadModule directives in your httpd.conf config file:

LoadModule bandwidth_module modules/mod_bandwidth.so

[...] The reason that the DLL could not be loaded is most often that it needs to load other DLL's it depends on to do its work. For example, the Oracle driver will want to load a number of Oracle DLL's. If these cannot be found at load time, this will result in error 1157. The official Windows description of this error code is:

ERROR_DLL_NOT_FOUND One of the library files needed to run this application cannot be found.

[...]Solution: Unfortunately, neither [Apache] nor Windows will tell you which DLL's could not be found. You will need to use some tool to find out. One possibility is to use a tool that traces the loading of DLL's or files. One such tool is NtFilmon, which is a shareware program that can be downloaded from http://www.sysinternals.com/. This site has a large number of high-quality troubleshooting tools that will come in handy with problems like these. 

If you have Microsoft Visual Studio 6.0 installed, the easiest way however is to right-click on the offending DLL and choose the View Dependencies option, if you have that. If it's not in your menu, you may have to start this program from the Microsoft Visual Studio 6.0 Tools menu (the program is called 'Dependency Walker' or 'Depends': [Depends tool icon]). [...]"

For mod_bandwidth.so it looks like this on my system:

[Dependency walker view]

Despite the red line for ApacheCore.dll, I did never have any trouble on my system. Maybe because other modules already load ApacheCore.dll before mod_bandwidth.so tries to do so, I don't know.

More about error 126 (and error 1157 for that matter)

Taking the advice found elsewhere, a possible solution might be in here: "In this case these were the libraries oci.dll and sqllib.dll. So you will have to make sure you have these DLL's in your search path. Note that these DLL's in turn may need other DLL's so this may be an iterative procedure. [...]" I.e. make sure both the Apache 'bin' and 'modules' directories are included in the PATH environment variable.

A bit more from abroad: "Note that this message does not always have to mean that the DLL's do not exist. In many cases, Windows uses the PATH environment variable to find additional DLL's, so it is worth checking if that variable contains the directories that contain your [...]-dependent DLL's. [...]

Background: Most of the [DLL's] are dependent on one or more DLL's provided by [others]. This dependency is compiled into the DLL (that is why you can see it with Dependency Walker). When Windows loads the driver DLL, it will also try to load these necessary DLL's. Typically, for this process to succeed, it is necessary that you have correctly installed the relevant [...] software. Generally speaking, simply copying in the missing files from another location (yes, some people do this stuff...) is not to be advised."

Still more quoting going on

Error 126:

"Problem: The specified file could be located, but could not be loaded. This essentially the same problem as error code 1157 described above. There does not seem to be any difference between the two situations, except that Windows NT reports error 126 and Windows 95/98 reports error 1157. We have not yet verified what Windows 2000 makes of this situation."

(Well, I personally use Windows 2000 and haven't had a 126... YET.

More quoting:

"The official Windows description of this error code is:

ERROR_MOD_NOT_FOUND The specified module could not be found.

Sometimes, but not always, this error is preceded by a Windows error box, saying that one or more DLL's could not be found in the search path. In many cases, Windows uses the PATH environment variable to find additional DLL's, so it is worth checking if that variable contains the directories that contain your [...]-dependent DLL's. On Windows NT, this is usually done when you install your [...] software, but it is worth checking out anyway.

Example of a Windows error box on NT:

[Windows Unable to Locate DLL dialog]

Solution: See above.

Background: See above."

[relevant System properties dialogs]

Or... you might be missing one of those Microsoft DLLs which those modules are looking for

So you verified your PATH environment variable, rebooted your machine yet error 126 persists. Maybe you're lacking one of the mandatory Microsoft DLLs Apache and/or its modules might be looking for:

System32\MSVCRT.DLL

System32\MSVCRTD.DLL

You may want to download those here (please don't overwrite the ones you already have: other programs might not wish to cooperate anymore then.)

NOTE: if you install these DLL's, make sure you copy them to the hidden System32\dllcache directory too if you're on Win2K (not tested on XP).

ADVICE: Another, probably better, way to make sure you have the latest and greatest DLLs from Microsoft is to download the VCredist.exe Visual C++ redistributable package and install that on your machine. Verify that after installation both MSVCRT.DLL and MSVCRTD.DLL are installed in your System32 directory! (More info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvc60/html/redistribvc6.asp)


Hope this helps anyone who suffers from error 126 while trying to install mod_bandwidth.so in his/her system.