Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5477 > unrolled thread
| Started by | Patrick Scheibe <pscheibe@trm.uni-leipzig.de> |
|---|---|
| First post | 2011-10-07 08:53 +0000 |
| Last post | 2011-10-10 09:54 +0000 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Wolfram LinkLibrary and additional dll on Windows Patrick Scheibe <pscheibe@trm.uni-leipzig.de> - 2011-10-07 08:53 +0000
Re: Wolfram LinkLibrary and additional dll on Windows "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-10-08 18:42 +0000
Re: Wolfram LinkLibrary and additional dll on Windows "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-10-08 18:42 +0000
Re: Wolfram LinkLibrary and additional dll on Patrick Scheibe <pscheibe@trm.uni-leipzig.de> - 2011-10-10 09:54 +0000
| From | Patrick Scheibe <pscheibe@trm.uni-leipzig.de> |
|---|---|
| Date | 2011-10-07 08:53 +0000 |
| Subject | Wolfram LinkLibrary and additional dll on Windows |
| Message-ID | <j6melm$7dj$1@smc.vnet.net> |
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/
[toc] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-10-08 18:42 +0000 |
| Message-ID | <j6q5i4$oud$1@smc.vnet.net> |
| In reply to | #5477 |
On Fri, 07 Oct 2011 09:53:10 +0100, Patrick Scheibe
<pscheibe@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.
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-10-08 18:42 +0000 |
| Message-ID | <j6q5j2$ouf$1@smc.vnet.net> |
| In reply to | #5477 |
On Fri, 07 Oct 2011 19:49:11 +0100, Oleksandr Rasputinov
<oleksandr_rasputinov@hmamail.com> wrote:
>
> 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.
Sorry: in option 3, LoadLibrary["tbb.dll"] should (obviously?) be
LibraryLoad["tbb.dll"]. I had mixed up the similarly named Windows
function with the Mathematica one.
In fact, LibraryLoad["tbb"] is probably better than
LibraryLoad["tbb.dll"], as this should work on all platforms provided that
the library can actually be found somewhere in $LibraryPath.
[toc] | [prev] | [next] | [standalone]
| From | Patrick Scheibe <pscheibe@trm.uni-leipzig.de> |
|---|---|
| Date | 2011-10-10 09:54 +0000 |
| Subject | Re: Wolfram LinkLibrary and additional dll on |
| Message-ID | <j6ufcp$gg1$1@smc.vnet.net> |
| In reply to | #5477 |
On Sat, 2011-10-08 at 05:33 -0400, Oleksandr Rasputinov wrote:
> On Fri, 07 Oct 2011 09:53:10 +0100, Patrick Scheibe
> <pscheibe@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web