Can multiple versions of MKL be used in the same process? - dll

We are developing a plugin for a 3rd party application in a Windows environment (each plugin is a DLL file stored in a predesignated folder). The application uses Intel MKL 10.3.9.1 internally, and ships with MKL DLLs in its installation folder.
Our plugin DLL also depends on MKL, but we must use a later version (11.1.3.1) because we use VS2012 (older versions of MKL do not support it). We place the MKL DLLs in the plugin folder, alongside our own DLL which is built against the said version of MKL. This is how our code links with MKL (in the x64 configuration):
#pragma comment(lib, "mkl_intel_lp64_dll")
#pragma comment(lib, "mkl_intel_thread_dll")
When the application runs, it loads the MKL 10.3 DLLs from its folder. When the plugin DLL is loaded it seems as though the MKL 11.1 DLLs are loaded (at least the files are accessed), but then the application freezes (if a debugger is attached, I see access violation exceptions). If the MKL-dependent portions of our code are replaced by stubs, effectively removing the dependency on MKL, the application runs and uses the plugin just fine.
My guess is that these problems arise because our DLL expects to work with MKL 11.1 but is actually getting the previously loaded MKL 10.3 (note that the DLLs of the different MKL versions have the same names).
Does anyone know if it is possible to load two different versions of MKL into the same process?

I managed to resolve this problem and allow our plugin to use a different version of MKL than that of the hosting application by taking the following steps (inspired by this thread, referred to by this answer - which describes a different but related scenario):
Put the MKL 11.1 DLLs in a subfolder under the plugin folder, called Intel.MKL (instead of the plugin folder itself, where our plugin DLL is stored).
Add a file named Intel.MKL.manifest in the said Intel.MKL folder with the following content:
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity name="Intel.MKL" processorArchitecture="amd64" version="11.1.3.1" type="win32" />
<file name="mkl_core.dll" />
<file name="mkl_intel_thread.dll" />
</assembly>
In the code of our plugin DLL, add this to some *.cpp file:
#pragma comment(linker, "/manifestDependency:\"name='Intel.MKL' processorArchitecture='amd64' version='11.1.3.1' type='win32' \"")
Keep the #pragma comments that refer to MKL's import libraries as they appear in the question. Also, there's no need to create a manifest for the MKL 10.3 DLLs in the application's own binary folder, and no need to touch the application EXE.
With these changes, I can see the application loads the MKL 10.3 DLLs from its own folder when it starts, and the MKL 11.1 DLLs from the Intel.MKL subfolder when the plugin is loaded. When calling mkl_get_version_string from the plugin, the expected version (11.1) is indeed returned.

Related

WiX versioning of DLL files which do not have .dll file extension

I am writing an installer for a plugin. The plugin is a set of dll files created with a SDK, and renamed to other extensions (such as .dlo, .dle). Using these extensions is mandatory so that the software recognizes them as plug-ins and loads them.
Unfortunately, WiX seems not to be recognizing those as DLL files, and does not manage versions. Which is an issue in my case, since some files are shared between different plugin releases which can be installed together, and must be at the version of the newest plugin release.
Is there a way to tell WiX that these are legit DLL files?

Unable to load DLL 'lua52': The specified module could not be found

I have the same problem as described here:
https://github.com/NLua/NLua/issues/33
Though I have followed the instructions to create a console application...
http://www.screencast.com/t/M12TqePQxW
...which works just fine, when I create a library project and reference it from another project (in this case, a Web API project) the following error occurs:
Unable to load DLL 'lua52': The specified module could not be found.
At this line:
using (var lua = new Lua())
How can a library project be made with the NLua nuget package without failing?
It is the exact same issue as described in the GitHub issue, the Nuget package is missing two DLLs that you need to use lua52.dll. One small difference, the current package (version 1.3.2.1) includes a newer version of lua52.dll that was built with VS2013. And therefore has a dependency on msvcr120.dll and msvp120.dll.
Beware that this may change in the future when Nuget updates your project.
As-is, you need to download and install the Visual C++ redistributable package for VS2013. Run both vcredist_x64.exe and vcredist_x86.exe so your project can run either in 32-bit or 64-bit mode.
To avoid having to do this on the machine on which you want to deploy your program, I recommend you copy the two DLLs from the c:\windows\system32 (64-bit) or c:\windows\syswow64 (32-bit) directories into the same directory as your EXE.
The package author could have done a better job putting this package together. Short from including the DLLs in the package, the better solution would be for him to rebuild lua52.dll with the /MT option so these dependencies are linked in. Consider clicking the New Issue button to let him know.

DLLNotFoundException - Unity3D Plugin

I'm getting a DLLNotFoundException in standalone builds on some windows machines, others work perfectly. Dll file is definitely in the plugins folder, copied it to the projectName_Data folder too but no difference.
Also attempted to add dll to streaming assets folder and set new path (Environment.SetEnvironmentVariable) as above but that didn't work either.
Using Unity 4.5.5 btw
Any help at all would be greatly appreciated!!!
What I found is that the error DllNotFoundException is, in some circumstances, very misleading. Unity is not to blame for this because when something goes wrong with dll loading, Unity simply doesn't have that dll in memory and tells you so.
As Keysosaurus says, Visual C++ Redistributable must be installed for your standalone version to work and in most cases this solves the trouble but there can be other reasons like third party dependencies.
In case you are using third party libraries then you must also copy all the needed DLLs or SOs to your executable's folder.
For example I am working with OpenNI 2 and when I build I immediately copy all files from C:\Program Files (x86)\OpenNI2\Redist folder to the folder that contains the .exe. Not doing this results in DllNotFoundException.
Also don't forget that DLLs (and SOs) must match the architecture you are targeting so if you are targeting x64 (64 bit) then your DLL must be x64 too and if you try to use a x86 (32 bit) DLL Unity will be confused and will not load that giving you the same error.
As a side note bear in mind that Unity 5 comes both in 32 and 64 bit versions. In order to run your game in Unity Editor, all third party libraries must be present in both x86 and x64 (in Unity's conventional folders) or at least the one that matches you Unity Editor's architecture.
I discovered that the problem was that players needed Visual C++ redistributable installed, which can be downloaded here:
https://www.microsoft.com/en-gb/download/details.aspx?id=40784

Which CUDA runtime DLL is used?

I have an application which use CUDA. I am using runtime API and CUDA toolkit 3.2. Application has a dependency on cudart32_32_7.dll. However, there is also cudart32_32_12.dll. The issue is, I do not know how to determine which dll is linked from cudart.lib during the application build. I need to identify dependency dynamically somehow, because I need to include all dependencies into the deployment package. I would like to avoid hard coding dependency path ...
Just put the .dll or .exe of your project into this software: Dependency walker. It will show on what other .dlls yours project depends on. There you'll find either cudart32_32_7.dll or cudart32_32_12.dll.
Alternatively, if you're making a binary project. Just compile it and run the binary (.exe) on a different machine that doesn't have CUDA installed. An error message will come asking for either cudart32_32_7.dll or cudart32_32_12.dll.

Linking against a .dll version older than the installed one in Visual Studio 2005

Please excuse the large amount of background info, but this is a fairly specific question.
I have a Visual Studio 2005 project that creates a .dll file. This project depends on a .dll from another company, "BigCorp", which gets installed with BigCorp's software.
Ideally the dll I create should be usable with any (backwards compatible) version of BigCorp's dll. That is, if I link against version 4.3.2.100 my program should still work if the user upgrades BigCorp's app so that the .dll is version 4.3.3.20.
This is straightforward enough in VS2005, by looking at the project's References, selecting the .dll and making sure the "Specific Version" property is false.
Now for my actual question: Is it possible to specify a base version of the .dll that is older than the one installed on the machine that is building the project? Continuing my previous example, my build machine has version 4.3.3.20 installed, but I want the .dll it generates to be compatible with installations that haven't upgraded, and only have version 4.3.2.100 installed.
It seems that VS resolves the path to the .dll and detects the runtime version based on the file it finds. Trying to override it by specifying the version number directly in the .vbproj or .csproj, i.e.,
<Reference Include="BigCorp.Program.Component, Version=4.3.2.100, Culture=neutral, PublicKeyToken=abc123def456654fed321cba, processorArchitecture=MSIL">
has no effect. Trying to register my assembly on a computer that has the older version fails with the good old "Could not load file or assembly" error because it tries to find the newer version of BigCorp's .dll.
Is what I want to do even possible?
You can do this by referencing the older DLL directly from the project, so copy the .dll file to your project, then reference it from there.
I do this all the time with my various development projects. Typically I'll put a "References" folder inside my project to hold referenced DLL's