Errors like the one shown above occur when an application encounters a different tbb.dll version than expected. So the important question to ask here is why does an application (or a MATLAB Compiler Standalone in particular here) encounter a different tbb.dll version than expected?
To be able to answer this it is first important to know how the Dynamic-Link Library Search Order works. Basically whenever an application tries to load a DLL, Windows will look for this DLL in the following locations in the following order (I only list the locations relevant for this discussion):
- The directory from which the application loaded.
- The Windows\System32 directory.
- The Windows directory.
- The current directory.
- Directories on the PATH environment variable.
Now both MATLAB and the MCR "try to be nice". They include tbb.dll in their bin\$arch directories which by default is not added to PATH and which obviously is also not the Windows(\System32) directory. So basically they cannot influence other applications.
Further when you run normal MATLAB through bin\matlab.exe this will underneath run bin\$arch\matlab.exe. So for MATLAB itself, tbb.dll is immediately found on "1. The directory from which the application (bin\$arch\matlab.exe) is loaded". So here nothing can go wrong.
For a MATLAB Compiler Standalone however this story is different. A standalone basically starts with loading mclmcrrtM_N.dll and this should be found on "5. Directories on the PATH" (MCR\runtime\$arch directory in this case). It then determines where bin\$arch is (relative to the location of mclmcrrtM_N.dll) and it adds this directory to the front of PATH (for the current application only, not the system wide setting). Then at a later point when tbb.dll gets loaded this is resolved in the following way:
- "The directory from which the application loaded." for a standalone this is the location containing yourStandalone.exe (which is not the MCR\bin\$arch directory). So by default tbb.dll is not found here. As suggested by Peter though you can place a manual copy here of the right version (the one included with MATLAB/MCR) to work around issues which could occur in the further steps.
- "The Windows\System32 directory." For things to work correctly tbb.dll should not be found here. Some other ("less nice" in terms of not trying to influence other applications) application may have decided to place a tbb.dll here though. In that case your standalone will get to see this tbb.dll. If that is an different version this can lead to the errors. (Note the emphasis on if, only if this is a different version an error can occur which may explain why things worked fine in R2013b but R2014a needed a workaround for "Image Analyst"). If you encounter an incorrect tbb.dll here you can consider removing this DLL such that the search continuous below or as mentioned under 1 place a correct copy next to the standalone.exe to prevent ever even getting to this point.
- The Windows directory. Basically the same story as the previous point. tbb.dll should not be found here but it could happen.
- "The current directory" often equal to "The directory from which the application loaded." but not necessarily so. This one hardly ever causes an issue though. But again tbb.dll should normally not be found here.
- "Directories on the PATH environment variable." now here tbb.dll should be found, more specifically in MCR\bin\$arch which the standalone added to its PATH at startup. (Note that PATH really is the last thing which is looked at which may explain why Ralph's approach did not work, he probably encountered a tbb.dll in Windows\System32).