Next: , Previous: , Up: C Interface   [Contents][Index]


5.26.5 Declaring OS-level libraries

For calling some C functions, you need to link with a specific OS-level library that contains that function. E.g., the sin function requires linking a special library by using the command line switch -lm. In our C iterface you do the equivalent thing by calling add-lib as follows:

clear-libs
s" m" add-lib
\c #include <math.h>
c-function sin sin r -- r

First, you clear any libraries that may have been declared earlier (you don’t need them for sin); then you add the m library (actually libm.so or somesuch) to the currently declared libraries; you can add as many as you need. Finally you declare the function as shown above. Typically you will use the same set of library declarations for many function declarations; you need to write only one set for that, right at the beginning.

Note that you must not call clear-libs inside c-library...end-c-library; however, c-library performs the function of clear-libs, so clear-libs is not necessary, and you usually want to put add-lib calls inside c-library...end-c-library.

clear-libs ( ) gforth-0.7 “clear-libs”

Clear the list of libs

add-lib ( c-addr u –  ) gforth-0.7 “add-lib”

Add library libstring to the list of libraries, where string is represented by c-addr u.

add-libpath ( c-addr u –  ) gforth-0.7 “add-libpath”

Add path string to the list of library search pathes, where string is represented by c-addr u.

add-incdir ( c-addr u –  ) gforth-1.0 “add-incdir”

Add path c-addr u to the list of include search pathes

add-cflags ( c-addr u –  ) gforth-1.0 “add-cflags”

add any kind of cflags to compilation

add-ldflags ( c-addr u –  ) gforth-1.0 “add-ldflags”

add flag to linker


Next: Callbacks, Previous: Defining library interfaces, Up: C Interface   [Contents][Index]