LibraryFunctionDeclaration
LibraryFunctionDeclaration ["extName",lib,type]
represents a function declaration that exposes the library function extName with the type type from the library lib, for use in compiled code.
LibraryFunctionDeclaration [name->"extName",lib,type]
aliases the function with name in compiled code.
LibraryFunctionDeclaration [nameSpec,type]
assumes that the library will be loaded by the time the function is compiled.
Details
- LibraryFunctionDeclaration is a symbolic representation of a declaration and does not evaluate on its own.
- LibraryFunctionDeclaration can be used inside of CompilerEnvironmentAppendTo and the first argument of functions like FunctionCompile .
- If name is not given, LibraryFunction ["extName"] is used.
- If the library has not already been loaded, then it will be loaded when a FunctionCompile is called.
- Libraries referenced by LibraryFunctionDeclaration run in the same process as the Wolfram Language kernel.
- FindLibrary is used to locate libraries found on $LibraryPath .
- When interfacing with libraries generated from C, it is preferable to use types such as "CInt" and "CFloat" instead of "Integer32" and "Real32", as the size of C types can vary on some platforms.
- LibraryLoad can be used to manually load a library. Functions from manually loaded libraries can be referenced by LibraryFunctionDeclaration without specifying the library. »
Examples
open allclose allBasic Examples (1)
Represent a declaration of a function from an external library:
Compile a program using the library function:
Scope (2)
Give the function an explicit name:
Load a library manually with LibraryLoad :
Create a LibraryFunctionDeclaration that references a function already loaded into the kernel:
Using the compiled function after unloading the library can lead to crashes.
Applications (1)
Represent a declaration of the SHA256 function from OpenSSL:
Compile a function that uses OpenSSL to compute the SHA256 hash of a string:
Compute the hash of a string:
Compare the computed hash with the built-in function Hash :
Tech Notes
Related Guides
History
Text
Wolfram Research (2022), LibraryFunctionDeclaration, Wolfram Language function, https://reference.wolfram.com/language/ref/LibraryFunctionDeclaration.html.
CMS
Wolfram Language. 2022. "LibraryFunctionDeclaration." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LibraryFunctionDeclaration.html.
APA
Wolfram Language. (2022). LibraryFunctionDeclaration. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LibraryFunctionDeclaration.html
BibTeX
@misc{reference.wolfram_2025_libraryfunctiondeclaration, author="Wolfram Research", title="{LibraryFunctionDeclaration}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/LibraryFunctionDeclaration.html}", note=[Accessed: 22-April-2025 ]}
BibLaTeX
@online{reference.wolfram_2025_libraryfunctiondeclaration, organization={Wolfram Research}, title={LibraryFunctionDeclaration}, year={2022}, url={https://reference.wolfram.com/language/ref/LibraryFunctionDeclaration.html}, note=[Accessed: 22-April-2025 ]}