Message Boards Message Boards

3
|
1983 Views
|
0 Replies
|
3 Total Likes
View groups...
Share
Share this post:

LibraryLoad: when not to use it

Posted 9 years ago

This is more of a warning to other people using LibraryLink than a question (but all comments are welcome).

The documentation is initially quite clear about what LibraryLoad is for:

LibraryLoad is used to load dependent dynamic libraries needed for a Wolfram Library to operate.

If I have a LibraryLink library that depends on other DLLs (.dylib files, .so files), those other DLLs must be explicitly loaded with LibraryLoad.

But then there is an example which loads a LibraryLink library, not its dependencies! LibraryLoad[ "demo"]. This implicitly suggests that it is at least okay to use LibraryLoad on LibraryLink libraries (before calling LibraryFunctionLoad), even if not necessary. What's not mentioned in the documentation is that doing this is harmful!

At least on OS X, if a LibraryLink library is loaded with LibraryLoad, it will no longer be possible to LibraryUnload it. There will not be any error messages on LibraryUnload, nor on any subsequent LibraryLoad or LibraryFunctionLoad calls. But if the library was modified, the modifications will not be picked up correctly after attempting to unload and re-load it.

A similar thing is reportedly happening on Linux as well: http://mathematica.stackexchange.com/q/38314/12 (though also calling LibraryFunctionLoad after LibraryLoad appears to fix the problem there).

I don't know almost anything about shared library loading mechanisms (any explanations/comments are most welcome!) but the conclusion seems to be:

There should be a warning in the documentation that says: never load a LibraryLink library using LibraryLoad! Use LibraryLoad only for the dependencies of a Wolfram Library, but never the Wolfram Library itself.

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract