add-library ( name path abi -- )
Factor documentation > Factor handbook > C library interface > Loading native libraries
Next:remove-library ( name -- )


Vocabulary
alien.libraries

Inputs and outputs
namea string
patha string
abione of cdecl or stdcall


Word description
Defines a new logical library named name located in the file system at path and the specified ABI. The logical library name can then be used by a LIBRARY: form to specify the logical library for subsequent FUNCTION: definitions.

Notes
Because the entire source file is parsed before top-level forms are executed, add-library must be placed within a << ... >> parse-time evaluation block.

This ensures that if the logical library is later used in the same file, for example by a FUNCTION: definition. Otherwise, the add-library call will happen too late, after compilation, and the C function calls will not refer to the correct library.

For details about parse-time evaluation, see Parse time evaluation.

Examples
Here is a typical usage of add-library:
<< "freetype" { { [ os macosx? ] [ "libfreetype.6.dylib" cdecl add-library ] } { [ os windows? ] [ "freetype6.dll" cdecl add-library ] } [ drop ] } cond >>

Note the parse time evaluation with <<.

Definition
USING: assocs kernel namespaces ;

IN: alien.libraries

: add-library ( name path abi -- )
3dup add-library? [
[ 2drop remove-library ]
[ <library> swap libraries get set-at ] 3bi
] [ 3drop ] if ;