({{, (RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad])[lib,fun,argtype,rettype]
loads Wolfram Library lib and makes the library function fun available in the Wolfram Language.}})

OpenersNotesSection(Spacer1)Details and Options

Arguments of (RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad]) are:

Possible argument and return types, and their corresponding C type, include:

LibraryFunctionLoad returns the (RefLink[LibraryFunction, paclet:ref/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 (RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad]) run in the same process as the Wolfram Language kernel.

Functions in libraries loaded by (RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad]) can make callbacks to the Wolfram Language.

Libraries loaded by (RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad]) can share data with the Wolfram Language kernel.

LibraryFunctionUnload unloads a LibraryFunction so that it can no longer be used.

Libraries loaded by (RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad]) are unloaded when the Wolfram Language kernel exits.

Libraries loaded by (RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad]) must be written as a dynamic library for the platform on which they run.

OpenersPrimaryExamplesSection(Spacer1)Examples  (4)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Load a function from a sample library:

fun=LibraryFunctionLoad["demo", "demo_I_I",{Integer},Integer]

Call the function:

fun[10]

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

LibraryFunctionLoad["demo", "demo_I_I",{Integer},Integer]

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

fun=LibraryFunctionLoad["demo_LinkObject","addtwo",LinkObject, LinkObject]

fun[1,2]

Load a function, which calls back to the Wolfram Language to evaluate (RefLink[Message, paclet:ref/Message])[MyFunction::info]:

MyFunction::info="This is the message: `1`";

fun=LibraryFunctionLoad["demo_eval","function1",{Integer,Integer}, Integer]

fun[1,2]

OpenersExampleSection2(Spacer1)Possible Issues  (1)

(RefLink[LibraryFunctionLoad, paclet:ref/LibraryFunctionLoad]) uses (RefLink[FindLibrary, paclet:ref/FindLibrary]) to locate libraries:

RepeatedTiming[LibraryFunctionLoad["demo","demo_I_I",{Integer},Integer]]

It is faster to find the library once with (RefLink[FindLibrary, paclet:ref/FindLibrary]):

lib=FindLibrary["demo"];
RepeatedTiming[LibraryFunctionLoad[lib,"demo_I_I",{Integer},Integer]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LibraryFunction, paclet:ref/LibraryFunction])  ▪  (RefLink[LibraryFunctionUnload, paclet:ref/LibraryFunctionUnload])  ▪  (RefLink[FindLibrary, paclet:ref/FindLibrary])  ▪  (RefLink[Function, paclet:ref/Function])  ▪  (RefLink[Compile, paclet:ref/Compile])  ▪  (RefLink[CompiledFunction, paclet:ref/CompiledFunction])  ▪  (RefLink[Install, paclet:ref/Install])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[LibraryLink User Guide, paclet:LibraryLink/tutorial/Overview])}, {▪(RefLinkPlain[Library Structure, paclet:LibraryLink/tutorial/LibraryStructure])}, {▪(RefLinkPlain[Interacting with the Wolfram System, paclet:LibraryLink/tutorial/InteractionWithWolframLanguage])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Wolfram LibraryLink, paclet:guide/LibraryLink])}, {▪(RefLinkPlain[C/C++ Language Interface, paclet:guide/CLanguageInterface])}, {▪(RefLinkPlain[Calling External Programs, paclet:guide/CallingExternalPrograms])}, {▪(RefLinkPlain[External Operations, paclet:guide/ExternalOperations])}})}})