LibraryFunctionLoad

LibraryFunctionLoad[lib, fun, argtype, rettype]
loads Wolfram Library lib and makes the library function fun available in Mathematica.

Details and OptionsDetails and Options

  • Arguments of LibraryFunctionLoad are:
  • liblibrary to be loaded
    funfunction name as specified in the library file
    argtypeslist of argument types
    rettypereturn type
  • Possible argument and return types, and their corresponding C type, include:
  • True|FalsemboolBoolean
    _Integermintmachine integer
    _Realdoublemachine double
    _Complexmcomplexmachine complex double
    {base,rank}MTensortensor of specified base type and rank
    "UTF8String"char*string in UTF-8 encoding
    LinkObjectMLINKarguments and result passed over MathLink
    "Void"voidno result (return only)
  • LibraryFunctionLoad returns the LibraryFunction object.
  • LibraryFunctionLoad can be called more than once with the same arguments returning the same LibraryFunction object.
  • LibraryFunctionLoad uses FindLibrary to locate libraries found on $LibraryPath.
  • When a Wolfram Library is loaded, an initialization function in the library is called.
  • When a Wolfram Library is unloaded, an uninitialization function in the library is called.
  • Libraries loaded by LibraryFunctionLoad run in the same process as the Mathematica kernel.
  • Functions in libraries loaded by LibraryFunctionLoad can make callbacks to Mathematica.
  • Libraries loaded by LibraryFunctionLoad can share data with the Mathematica kernel.
  • LibraryFunctionUnload unloads a LibraryFunction so that it can no longer be used.
  • Libraries loaded by LibraryFunctionLoad are unloaded when the Mathematica kernel exits.
  • Libraries loaded by LibraryFunctionLoad must be written as a dynamic library for the platform on which they run.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Load a function from a sample library:

In[1]:=
Click for copyable input
Out[1]=

Call the function:

In[2]:=
Click for copyable input
Out[2]=

You can call LibraryFunctionLoad more than once for the same input:

In[3]:=
Click for copyable input
Out[3]=

Load a function from the library, which will exchange data over MathLink:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Load a function, which calls back to Mathematica to evaluate Message[MyFunction::info]:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
New in 8
New to Mathematica? Find your learning path »
Have a question? Ask support »