6.32.6 C compiler and linker options

Sometimes you need to pass additional options to the C compiler for compiling or linking a library.

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 interface you do the equivalent thing by calling add-lib as follows:

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

The add-lib call adds the -lm to the linker command line, such that the library libm.so (or somesuch) is linked with the new library; you can add as many as you need. Finally you declare the function as shown above. All words inside the c-library...end-c-library can use functions from this library (or these libraries).

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

Add -lstring to the linker call for the current library, where string is represented by c-addr u. I.e., link with libstring.so or somesuch.

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

Add -Lstring to the linker call for the current library, where string is represented by c-addr u. I.e., add string to the directories that are searched for C libraries specified with add-lib.

add-framework ( c-addr u –  ) gforth-1.0

Add -framework string (see Darwin Options in Using the GNU Compiler Collection) to the compiler call for the current library, where string is represented by c-addr u.

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

Add -Istring to the compiler call for the current library, where string is represented by c-addr u. I.e., add string to the directory where the C compiler searches for .h files.

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

Add the string c-addr u to the currently used flags for C compilation.

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

Add the string c-addr u to the currently used flags for C linking.