add-library ( name path abi -- )
Factor handbook » C library interface » Loading native libraries

Next:remove-library ( name -- )


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. You can find the location of the library via words in alien.libraries.finder. The logical library name can then be used by a LIBRARY: form to specify the logical library for subsequent FUNCTION: definitions.

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.

Here is a typical usage of add-library:
<< "sqlite" "sqlite3" find-library cdecl add-library >>

You can also explicitly specify the library name by platform, if you prefer:
<< "freetype" { { [ os macosx? ] [ "libfreetype.6.dylib" cdecl add-library ] } { [ os windows? ] [ "freetype6.dll" cdecl add-library ] } [ drop ] } cond >>

Note the parse time evaluation with <<.