Re: Wolfram LinkLibrary and additional dll on
- To: mathgroup at smc.vnet.net
- Subject: [mg122045] Re: Wolfram LinkLibrary and additional dll on
- From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
- Date: Mon, 10 Oct 2011 05:53:32 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j6melm$7dj$1@smc.vnet.net> <201110080933.FAA20999@smc.vnet.net>
On Sat, 2011-10-08 at 05:33 -0400, Oleksandr Rasputinov wrote: > On Fri, 07 Oct 2011 09:53:10 +0100, Patrick Scheibe > <pscheibe at trm.uni-leipzig.de> wrote: > > > Hi, > > > > I have a package which has its number crunching algorithms in a C++ > > library which is connected to Mathematica through the LibraryLink. > > Inside my algorithms I use the Intel Threading building blocks > > [1] heavily. I have this library compiled for Linux, Mac OSX and Windows > > and inside each LibraryResources directory, I distribute the tbb.{so | > > dylib | dll}. Everythings works fine except for 2 Windows machines. > > On those two machines the Intel compiler tools are not installed and > > therefore, my lib has to rely on the > > tbb.dll which is distributed in the same directory. > > > > Loading the package brings up an error dialog, that says that the > > tbb.dll could not be found. > > > > 1. Using FindLibrary["tbb"] brings up the correct path inside my package. > > > > 2. Taking any arbitrarily chosen function from the tbb and register it > > with, for instance > > > > LibraryFunctionLoad["tbb", "TBB_runtime_interface_version", {}, Integer]; > > > > and *then* loading my package, works without error. > > > > 3. Trying to put this preload inside the WolframLibrary_initialize > > function with something like > > > > #if defined(_WIN32) || defined(_WIN64) > > tbbLib = LoadLibrary("tbb.dll"); > > if(tbbLib != NULL) { > > tbbInitializeFunctionType version = (tbbInitializeFunctionType) > > GetProcAddress(tbbLib, > > "TBB_runtime_interface_version"); > > char msg[100]; > > sprintf(msg,"Die TBB version ist: %d\n",version()); > > lib->Message(msg); > > } > > #endif > > > > does not work. Maybe important at this point is, that there is no longer > > an "error dialog" coming up. There > > is now only an Mathematica error message saying, that the library > > function could not be loaded. I assume my > > dll is crashed silently. On the other > > windows machines with the intel compiler installed everything works fine > > and the version number is displayed > > when the library is loaded first. > > > > 4. The dependency walker says that everything is fine with my library. > > No wrong modules and the tbb comes from the directory > > where my library is located > > > > 5. Trying to profile math.exe with the dependency walker and loading my > > package does not bring any useful information. > > In fact, I don't see any dlopen or whatsoever when I load my package. > > This *suggests* that the tbb is not found in the first > > place, but this is only a guess and I don't understand this. > > > > > > I'm not a Windows guy and I'm not a soldier in the dll-hell, so can > > someone please give me a helping hand here or point me to > > some useful documentation? Do I maybe need to create a special manifest > > file? Does it make a difference whether a > > dll is not loaded by Mathematica directly, but through another dll? > > > > Currently I'm out of ideas how to track this down. > > > > Cheers > > Patrick > > > > [1] http://software.intel.com/en-us/articles/intel-tbb/ > > The issue may be that LoadLibrary("tbb.dll") fails due to not locating > tbb.dll on the search path--note that Windows's search path and > Mathematica's $LibraryPath are in general very different (for example, on > my system they contain nothing in common). If this is the case, then as I > see it you have at least three options: > > 1. set the Windows search path to $LibraryPath using SetDllDirectory() > before calling LoadLibrary() (here I assume that you would rather not > hard-code a fully qualified path due to possible difference between > installations); > 2. load the library using LoadLibrary(), but giving a fully qualified path > to the file as found by FindLibrary[]; > 3. use LoadLibrary["tbb.dll"] as part of your package initialization to > have Mathematica do this for you before you load your own library. > > Of these, option 3 seems preferable to me. Actually, I'm surprised that > LibraryFunctionLoad worked on tbb.dll considering that this will not > contain any WolframLibrary_initialize function or indeed adhere to the > Wolfram Library specification in any other respect. > Hi Oleksandr, thanks for your mail. The problem was, that the dumb thing behind the keyboard (aka me) was unable to recheck the documentation. I read it once and thought I had grasped the importand details. Fail. The LinkLibrary tutorial cries it out loudly here LibraryLink/tutorial/InteractionWithMathematica#162865056 and confirms, that you were right. The problem were the different paths. The hack, which a friend suggested, namly to preload the tbb.dll with a first call to LibraryLoad *is* an actual solution. Quote: "An alternative is to use LibraryLoad to load the dependent libraries before loading your own library. LibraryLoad does not return a function (unlike LibraryFunctionLoad), it merely exists to load dependent libraries." Thank you very much for your help. Cheers Patrick
- References:
- Re: Wolfram LinkLibrary and additional dll on Windows
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
- Re: Wolfram LinkLibrary and additional dll on Windows